Newer
Older
DirtyScripts / graph-explorer-sites-list-compare.php
root on 29 Jun 2020 1 KB JSON AJAX PoC added
  1. #!/usr/bin/php
  2. <?php
  3. error_reporting(0);
  4.  
  5. /***
  6. * Small script to create graph from multiple users JSON's taken from MS Graph Explorer
  7. * (Search for a SharePoint site by keyword) keyword = %00
  8. ***/
  9.  
  10. $folder = "/mnt/hgfs/PentestOS/pentests/2020/Devon/MS_Graph/";
  11.  
  12. $mainArray = array();
  13.  
  14. $rootDir = getDirContents($folder, '/\.json$/');
  15. foreach($rootDir as $h => $i){ // remove begining of vdb path (keeps clean)
  16. $rootDir[$h] = str_replace("sites_null_", "", str_replace(".json", "", str_replace($folder, "", $i)));
  17. //echo "Reading: ".$rootDir[$h]."\n";
  18.  
  19. $jsonFile = file_get_contents($i);
  20. $jsonContents = json_decode($jsonFile, true);
  21.  
  22. foreach($jsonContents as $j){
  23. foreach($j as $k){
  24. //echo " ".$k['name']." -> ".$k['webUrl']."\n";
  25. $shortname[$k['name']] = $k['webUrl'];
  26. $rarw[$k['name']][] = $rootDir[$h];
  27. }
  28. //print_r($j);
  29. }
  30. }
  31. echo "Files: ".sizeof($rootDir)."\n";
  32.  
  33. foreach($shortname as $short => $long){
  34. $lenToShow = 120;
  35. if(strlen($long)<$lenToShow)
  36. $long = str_pad($long, $lenToShow, "-");
  37. echo substr($long, 0, $lenToShow)." -> ";
  38. //print_r($rarw[$short]);
  39. foreach($rarw[$short] as $shortname => $username){
  40. echo $username." ";
  41.  
  42. }
  43. echo "\n";
  44. }
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52. function getDirContents($dir, $filter = '', &$results = array()) {
  53. $files = scandir($dir);
  54.  
  55. foreach($files as $key => $value){
  56. $path = realpath($dir.DIRECTORY_SEPARATOR.$value);
  57.  
  58. if(!is_dir($path)) {
  59. if(empty($filter) || preg_match($filter, $path)) $results[] = $path;
  60. } elseif($value != "." && $value != "..") {
  61. getDirContents($path, $filter, $results);
  62. }
  63. }
  64.  
  65. return $results;
  66. }
  67.  
  68. ?>
Buy Me A Coffee