Advertisement
Guest User

Untitled

a guest
Apr 9th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.50 KB | None | 0 0
  1. <?php
  2. // PHPDOM -
  3. // post - http://stackoverflow.com/questions/28395/passing-post-values-with-curl
  4. // OCR  - https://github.com/thiagoalessio/tesseract-ocr-for-php
  5. require_once './vendor/autoload.php';
  6.  
  7. use PHPHtmlParser\Dom;
  8.  
  9. class AlphabayBot {
  10.     public $website_url = '';
  11.     public $proxy_port = '9050';
  12.     public $proxy_address = '127.0.0.1';
  13.  
  14.     // contain curl connection
  15.     private $ch = null;
  16.     // contain DOM class
  17.     private $dom = null;
  18.     // contain page out put (HTML)
  19.     private $page_output;
  20.     // users txt file
  21.     private $users;
  22.  
  23.     function __construct($website_url, $proxy_port, $proxy_address) {
  24.         // set wensite url
  25.         $this->website_url = $website_url;
  26.         // set proxy port
  27.         $this->proxy_port = $proxy_port;
  28.         // set proxy address
  29.         $this->proxy_address = $proxy_address;
  30.  
  31.         // create new curl instance
  32.         $this->ch = curl_init();
  33.         // new Dom instance
  34.         $this->dom = new Dom;
  35.         // set page output as null
  36.         $this->page_output = null;
  37.         // load users txt file (contain all registered users)
  38.         $this->users = 'users.txt';
  39.     }
  40.  
  41.     function set_random_user_agent() {
  42.         $agents = array(
  43.         'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:7.0.1) Gecko/20100101 Firefox/7.0.1',
  44.         'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.9) Gecko/20100508 SeaMonkey/2.0.4',
  45.         'Mozilla/5.0 (Windows; U; MSIE 7.0; Windows NT 6.0; en-US)',
  46.         'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; da-dk) AppleWebKit/533.21.1 (KHTML, like Gecko) Version/5.0.5 Safari/533.21.1'
  47.         );
  48.         curl_setopt($this->ch,CURLOPT_USERAGENT,$agents[array_rand($agents)]);
  49.     }
  50.  
  51.     function get_login_page_content() {
  52.         // taken from here - http://stackoverflow.com/questions/23155543/sending-post-get-with-php-to-tor
  53.         curl_setopt ($this->ch, CURLOPT_URL, $this->website_url);
  54.         curl_setopt ($this->ch, CURLOPT_HEADER, 0);
  55.         curl_setopt ($this->ch, CURLOPT_PROXYTYPE, 7 );
  56.        
  57.         curl_setopt ($this->ch, CURLOPT_PROXY,
  58.             $this->proxy_address.':'.$this->proxy_port );
  59.        
  60.         curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, TRUE);
  61.         ob_start();
  62.         curl_exec ($this->ch);
  63.         $result = ob_get_contents();
  64.         ob_end_clean();
  65.         $this->page_output = $result;
  66.         // load html content to DOM class.
  67.         $this->dom->load($this->page_output);
  68.     }
  69.  
  70.     function decoding_captcha() {
  71.         // captcha full url
  72.         $get_captcha_img = $this->dom->find('#captcha')['0'];
  73.        
  74.         // if captcha exists for alpha home page login
  75.         if( !empty($get_captcha_img) ) {
  76.             // get captcha image url
  77.             $captcha_full_url = $this->website_url . $get_captcha_img->src;
  78.             // save image to server
  79.             // save file with curl - http://stackoverflow.com/questions/724391/saving-image-from-php-url        
  80.             // create image temporary name with time()
  81.             $image_tmp_name = time() . '.png';
  82.             // create temp image file
  83.             $fp = fopen('./tmp/' . $image_tmp_name, 'wb');
  84.             curl_setopt($this->ch, CURLOPT_TIMEOUT, 50);
  85.             // write curl response to file
  86.             curl_setopt ($this->ch, CURLOPT_URL, $captcha_full_url);
  87.             curl_setopt($this->ch, CURLOPT_FILE, $fp);
  88.             fclose($fp);        
  89.         }
  90.        
  91.         curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, true);
  92.         // get curl response
  93.         curl_exec($this->ch);
  94.     }
  95.  
  96.     /*
  97.      * post_login_credentials - send uer and password credentials and login forum
  98.      */
  99.     function post_login_credentials() {
  100.         // get inputs by id
  101.         $login_email = $this->dom->find('#ctrl_pageLogin_login')['0'];
  102.         $login_password = $this->dom->find('#ctrl_pageLogin_password')['0'];
  103.  
  104.         if( ! empty($login_email) || ! empty($login_password) ) {
  105.             echo "\n\n";
  106.             echo 'found input names: ' . "\n\n";
  107.             echo $login_email->name . "\n\n";
  108.             echo $login_password->name . "\n\n";
  109.  
  110.             $user = $this->return_registered_user();
  111.             echo "\n\n";
  112.             echo 'this user selected: ' . $user['login'] . "\n";
  113.             echo 'this password selected: ' . $user['password'] . "\n";
  114.  
  115.             $this->make_login(
  116.                 $login_email->name,
  117.                 $login_password->name,
  118.                 $user['login'],
  119.                 $user['password']
  120.             );
  121.  
  122.             curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, true);
  123.             $url_redirect = curl_getinfo($this->ch , CURLINFO_EFFECTIVE_URL);
  124.             echo "\n\n";
  125.             echo 'url after redirect:';
  126.             echo "\n";
  127.             print_r( $this->bot_debug() );
  128.             return true;
  129.         }
  130.         else {
  131.             echo 'login user/email and password inputs not found.';
  132.             return false;
  133.         }
  134.  
  135.     }
  136.  
  137.     function bot_debug() {
  138.         curl_setopt($this->ch, CURLINFO_HEADER_OUT, true);
  139.         return curl_getinfo($this->ch);
  140.     }
  141.  
  142.     function make_login($login_input, $password_input,$login, $password) {
  143.         $data = array(
  144.             $login_input    => $login,
  145.             $password_input => $password
  146.         );
  147.  
  148.         curl_setopt($this->ch, CURLOPT_POST, true);
  149.         curl_setopt($this->ch, CURLOPT_POSTFIELDS, $data);
  150.         print_r( $this->bot_debug() );
  151.         curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, true);
  152.         // check where do i redirect
  153.         echo 'logged in with this user and password:' . "\n";
  154.         echo 'user: ' . $login . "\n";
  155.         echo 'password: ' . $password . "\n";
  156.         echo "\n\n\n";
  157.         echo '--- url redirection to login ---';
  158.         echo "\n\n\n";
  159.         $url_redirect = curl_getinfo($this->ch , CURLINFO_EFFECTIVE_URL);
  160.         ob_start();
  161.         curl_exec($this->ch);
  162.         ob_get_contents();
  163.         ob_end_clean();
  164.         echo "\n";
  165.         echo 'url redirect: ';
  166.         echo "\n";
  167.         print_r($url_redirect);
  168.         echo "\n";
  169.     }
  170.  
  171.     function return_registered_user($user_number=null) {
  172.         $lines_num = count( file( $this->users ) ) - 1;
  173.         // if ! $user_number then select user from file randomly
  174.         $users_file = file( $this->users );
  175.         if( ! $user_number ) {
  176.             $line = $users_file[rand(0, $lines_num - 1)];
  177.         }
  178.         else {
  179.             // select by $user_number
  180.             $line = $users_file[$user_number];
  181.         }
  182.         // explode user and password from the line
  183.         $user = explode("   ", $line);
  184.         // load user from users.txt
  185.         return array(
  186.             'login' => $user[0],
  187.             'password' => $user[1]
  188.         );
  189.     }
  190.  
  191.     // return array of new users
  192.     function find_new_users() {
  193.  
  194.     }
  195.  
  196.     function send_private_message($msg, $user) {
  197.  
  198.     }
  199.  
  200.     function close() {
  201.         curl_close($this->ch);
  202.     }
  203. }
  204.  
  205. echo '<pre>';
  206. // PROXY AND
  207. $proxy_address = "127.0.0.1";
  208. $proxy_port = "9050";
  209. // AlphaBay login url
  210. $website_url = "https://xenforo.com/community/";
  211.  
  212. $a_bot = new AlphabayBot($website_url, $proxy_port, $proxy_address);
  213. // set random user agent
  214. $a_bot->set_random_user_agent();
  215. // get captcha url
  216. $a_bot->get_login_page_content();
  217.  
  218. // decoding captcha
  219. // $a_bot->decoding_captcha(); - not necessary now
  220.  
  221. // login with user and password
  222. $a_bot->post_login_credentials();
  223. // close curl connection
  224. $a_bot->close();
  225. echo "\n";
  226. echo '</pre>';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement