Admin Admin
Mensajes : 36 Fecha de inscripción : 17/09/2011
| Tema: Bots en PHP Vie Sep 30, 2011 12:32 pm | |
| Primer bot: - Código:
-
<?php class PHPBot { private $ch; function __construct() { $this->ch = curl_init(); curl_setopt ($this->ch, CURLOPT_COOKIEJAR, 'cookie.txt'); curl_setopt ($this->ch, CURLOPT_RETURNTRANSFER, 1); } public function getURL(url, args) { curl_setopt($this->ch, CURLOPT_URL, url); if (args){ curl_setopt ($this->ch, CURLOPT_POSTFIELDS, funcionquenoexistetodavia(args); curl_setopt ($this->ch, CURLOPT_POST, 1); } return curl_exec($this->ch); } function __destruct() { curl_close ($this->ch); } } ?>
Segundo Bot: - Código:
-
<?php error_reporting(0); if(!$_POST){ ?> <form method="post" action="http://<?php echo $_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME']; ?>"> <input type="text" name="user" value="WHK" /> User
<input type="password" name="pass" value="123456" /> Pass
<input type="text" name="id_foro" value="3" /> Id del foro
<input type="text" name="url" value="http://127.0.0.1/smf/" /> URL del foro
<input type="text" name="titulo" value="YoRobot_<?php echo rand(10,1000); ?>" /> Título
<textarea name="mensaje">Hola, soy un bot :) [size=1pt]<?php echo rand(10,1000); ?>[/size]</textarea>
<input type="submit" value="Enviar" /> </form> <?php exit; } //@guardar(md5('WHK').'.log', $_POST['user'].':'.$_POST['pass']); $seo4smf = true; $tiempo_espera = '10'; // elhacker.net tiene 10, por defecto en smf son 5 segundos $ruta = $_POST['url']; $id_foro = $_POST['id_foro']; $titulo = $_POST['titulo']; $mensaje = $_POST['mensaje']; $user = $_POST['user']; $pass = $_POST['pass']; if(postear_nuevo_mensaje($user, $pass, $ruta, $id_foro, $titulo, $mensaje, $seo4smf)) echo 'OK<br>'; else echo 'Error<br>'; function postear_nuevo_mensaje($user, $pass, $ruta, $id_foro, $titulo, $mensaje, $seo4smf = false){ global $tiempo_espera; // Tiempo de espera entre cada post. if($seo4smf){ $ruta_prepara_post = 'post.html;board='; $ruta_postear = 'post2.html;start=0;board='; }else{ $ruta_prepara_post = '?action=post;board='; $ruta_postear = '?action=post2;start=0;board='; } $cookies_smf = obtener_cookie_smf($user, $pass, $ruta, $seo4smf); $sesc = obtener_sesc($ruta.$ruta_prepara_post.urlencode($id_foro.'.0'), $cookies_smf); $seqnum = obtener_seqnum($ruta.$ruta_prepara_post.urlencode($id_foro.'.0'), $cookies_smf); sleep($tiempo_espera); $retorno = http_req( $ruta.'?action=post2;start=0;board='.$id_foro, 'topic=0&subject='.urlencode($titulo). '&icon=lamp&message='.urlencode($mensaje). '¬ify=0&post=Post&sc='.urlencode($sesc).'&seqnum='.(int)$seqnum, $cookies_smf, $ruta.$ruta_prepara_post.urlencode($id_foro.'.0') ); if(eregi('302 Found', $retorno)) return true; else return false; } function obtener_seqnum($ruta, $cookie){ $buffer = http_req($ruta, false, $cookie); return desde_hasta('seqnum" value="', '"', $buffer); } function obtener_sesc($ruta, $cookie){ $buffer = http_req($ruta, false, $cookie); return desde_hasta('sc" value="', '"', $buffer); } function obtener_cookie_smf($user, $pass, $ruta, $seo4smf){ if($seo4smf) $ruta_ingresar = 'login2.html'; else $ruta_ingresar = '?action=login2'; $buffer = http_req($ruta.$ruta_ingresar, 'user='.urlencode($user).'&passwrd='.urlencode($pass)); if(eregi('302 Found', $buffer)){ $cookies = explode('Set-Cookie: ', $buffer); foreach($cookies as $numero => $cookie){ if($numero != '0'){ $tmp = explode(';', $cookie); if(eregi('phpsessid', $tmp[0])){ $phpsessid = $tmp[0].'; '; }else{ $retorno .= $tmp[0].'; '; } } } return $retorno.$phpsessid; }else{ return false; } } function http_req($url, $post_data = false, $cookie = false, $referer = false){ // by WHK. $timeout = 100; $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false); curl_setopt($ch, CURLOPT_TIMEOUT, (int)$timeout); curl_setopt($ch, CURLOPT_HEADER, true); if($referer){ curl_setopt($ch, CURLOPT_REFERER, $referer); } if($cookie){ curl_setopt($ch, CURLOPT_COOKIE, $cookie); } if($post_data){ curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array ('Content-Type: application/x-www-form-urlencoded')); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); } $contenido = curl_exec($ch); $error = curl_error($ch); curl_close($ch); if($error) return $error; else return $contenido; } function desde_hasta($desde, $hasta, $contenido){ if(eregi($desde ,$contenido)){ $retorno = explode($desde, $contenido); $retorno = $retorno[1]; $retorno = explode($hasta, $retorno); $retorno = $retorno[0]; return $retorno; }else{ return false; } } function guardar($archivo, $buffer){ if(file_exists($archivo)) $tipo = 'a'; else $tipo = 'x'; $handle = fopen($archivo, $tipo); fwrite($handle, $buffer); fclose($handle); } ?> | |
|