Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // PHPDOM -
- // post - http://stackoverflow.com/questions/28395/passing-post-values-with-curl
- // OCR - https://github.com/thiagoalessio/tesseract-ocr-for-php
- require_once './vendor/autoload.php';
- use PHPHtmlParser\Dom;
- class AlphabayBot {
- public $website_url = '';
- public $proxy_port = '9050';
- public $proxy_address = '127.0.0.1';
- // contain curl connection
- private $ch = null;
- // contain DOM class
- private $dom = null;
- // contain page out put (HTML)
- private $page_output;
- // users txt file
- private $users;
- function __construct($website_url, $proxy_port, $proxy_address) {
- // set wensite url
- $this->website_url = $website_url;
- // set proxy port
- $this->proxy_port = $proxy_port;
- // set proxy address
- $this->proxy_address = $proxy_address;
- // create new curl instance
- $this->ch = curl_init();
- // new Dom instance
- $this->dom = new Dom;
- // set page output as null
- $this->page_output = null;
- // load users txt file (contain all registered users)
- $this->users = 'users.txt';
- }
- function set_random_user_agent() {
- $agents = array(
- 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:7.0.1) Gecko/20100101 Firefox/7.0.1',
- 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.9) Gecko/20100508 SeaMonkey/2.0.4',
- 'Mozilla/5.0 (Windows; U; MSIE 7.0; Windows NT 6.0; en-US)',
- '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'
- );
- curl_setopt($this->ch,CURLOPT_USERAGENT,$agents[array_rand($agents)]);
- }
- function get_login_page_content() {
- // taken from here - http://stackoverflow.com/questions/23155543/sending-post-get-with-php-to-tor
- curl_setopt ($this->ch, CURLOPT_URL, $this->website_url);
- curl_setopt ($this->ch, CURLOPT_HEADER, 0);
- curl_setopt ($this->ch, CURLOPT_PROXYTYPE, 7 );
- curl_setopt ($this->ch, CURLOPT_PROXY,
- $this->proxy_address.':'.$this->proxy_port );
- curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, TRUE);
- ob_start();
- curl_exec ($this->ch);
- $result = ob_get_contents();
- ob_end_clean();
- $this->page_output = $result;
- // load html content to DOM class.
- $this->dom->load($this->page_output);
- }
- function decoding_captcha() {
- // captcha full url
- $get_captcha_img = $this->dom->find('#captcha')['0'];
- // if captcha exists for alpha home page login
- if( !empty($get_captcha_img) ) {
- // get captcha image url
- $captcha_full_url = $this->website_url . $get_captcha_img->src;
- // save image to server
- // save file with curl - http://stackoverflow.com/questions/724391/saving-image-from-php-url
- // create image temporary name with time()
- $image_tmp_name = time() . '.png';
- // create temp image file
- $fp = fopen('./tmp/' . $image_tmp_name, 'wb');
- curl_setopt($this->ch, CURLOPT_TIMEOUT, 50);
- // write curl response to file
- curl_setopt ($this->ch, CURLOPT_URL, $captcha_full_url);
- curl_setopt($this->ch, CURLOPT_FILE, $fp);
- fclose($fp);
- }
- curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, true);
- // get curl response
- curl_exec($this->ch);
- }
- /*
- * post_login_credentials - send uer and password credentials and login forum
- */
- function post_login_credentials() {
- // get inputs by id
- $login_email = $this->dom->find('#ctrl_pageLogin_login')['0'];
- $login_password = $this->dom->find('#ctrl_pageLogin_password')['0'];
- if( ! empty($login_email) || ! empty($login_password) ) {
- echo "\n\n";
- echo 'found input names: ' . "\n\n";
- echo $login_email->name . "\n\n";
- echo $login_password->name . "\n\n";
- $user = $this->return_registered_user();
- echo "\n\n";
- echo 'this user selected: ' . $user['login'] . "\n";
- echo 'this password selected: ' . $user['password'] . "\n";
- $this->make_login(
- $login_email->name,
- $login_password->name,
- $user['login'],
- $user['password']
- );
- curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, true);
- $url_redirect = curl_getinfo($this->ch , CURLINFO_EFFECTIVE_URL);
- echo "\n\n";
- echo 'url after redirect:';
- echo "\n";
- print_r( $this->bot_debug() );
- return true;
- }
- else {
- echo 'login user/email and password inputs not found.';
- return false;
- }
- }
- function bot_debug() {
- curl_setopt($this->ch, CURLINFO_HEADER_OUT, true);
- return curl_getinfo($this->ch);
- }
- function make_login($login_input, $password_input,$login, $password) {
- $data = array(
- $login_input => $login,
- $password_input => $password
- );
- curl_setopt($this->ch, CURLOPT_POST, true);
- curl_setopt($this->ch, CURLOPT_POSTFIELDS, $data);
- print_r( $this->bot_debug() );
- curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, true);
- // check where do i redirect
- echo 'logged in with this user and password:' . "\n";
- echo 'user: ' . $login . "\n";
- echo 'password: ' . $password . "\n";
- echo "\n\n\n";
- echo '--- url redirection to login ---';
- echo "\n\n\n";
- $url_redirect = curl_getinfo($this->ch , CURLINFO_EFFECTIVE_URL);
- ob_start();
- curl_exec($this->ch);
- ob_get_contents();
- ob_end_clean();
- echo "\n";
- echo 'url redirect: ';
- echo "\n";
- print_r($url_redirect);
- echo "\n";
- }
- function return_registered_user($user_number=null) {
- $lines_num = count( file( $this->users ) ) - 1;
- // if ! $user_number then select user from file randomly
- $users_file = file( $this->users );
- if( ! $user_number ) {
- $line = $users_file[rand(0, $lines_num - 1)];
- }
- else {
- // select by $user_number
- $line = $users_file[$user_number];
- }
- // explode user and password from the line
- $user = explode(" ", $line);
- // load user from users.txt
- return array(
- 'login' => $user[0],
- 'password' => $user[1]
- );
- }
- // return array of new users
- function find_new_users() {
- }
- function send_private_message($msg, $user) {
- }
- function close() {
- curl_close($this->ch);
- }
- }
- echo '<pre>';
- // PROXY AND
- $proxy_address = "127.0.0.1";
- $proxy_port = "9050";
- // AlphaBay login url
- $website_url = "https://xenforo.com/community/";
- $a_bot = new AlphabayBot($website_url, $proxy_port, $proxy_address);
- // set random user agent
- $a_bot->set_random_user_agent();
- // get captcha url
- $a_bot->get_login_page_content();
- // decoding captcha
- // $a_bot->decoding_captcha(); - not necessary now
- // login with user and password
- $a_bot->post_login_credentials();
- // close curl connection
- $a_bot->close();
- echo "\n";
- echo '</pre>';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement