Jump to content
pyth0n3

[Python] myknock.py client

Recommended Posts

Posted

Description:

Makes port-hits by sending a TCP packet with syn flag set .

#!/usr/bin/python
#Author: pyth0n3
#Date:19.09.2011
#Purpose:Knock client (SYN-sequence)

from __future__ import print_function
import logging
logging.getLogger('scapy.runtime').setLevel(logging.ERROR)
import sys
import socket
try:
from scapy.all import IP,TCP,sr1
except ImportError:
print('[+] Need to install python-scapy first')
print('[+] http://www.secdev.org/projects/scapy/')
sys.exit()

def display():
print('#'*50)
hand = '\n# Usage: myknock.py <ip> <seq 1> <seq 2> <seq n> #\n#'
print('#',' '*47 + '#',hand ,' '*47 +'#')
print('#'*50)
sys.exit()

if len(sys.argv) < 3:
display()


seq = sys.argv[2:]
addr = sys.argv [1]


try:
socket.inet_aton(addr)
except socket.error:
print ('[+] You have entered an ilegal address')
sys.exit()


def getinteger(n):
try:
return int(n)
except ValueError:
print ('[+] Bad sequence numbers')
sys.exit()

ports = map(getinteger,seq)

hand = range(1,65536)
for sq in ports:
if sq in hand:
pass
else:
print('[+] Sequence out of range')
sys.exit()

def session():
i = IP()
i.dst=addr
t = TCP()
t.dport = ports
t.flags = 'S'
get = sr1(i/t,timeout=1)
print('[+] Knock done!')

if __name__ == '__main__':
session()


Download:

wget http://sprunge.us/QNDJ -O mycknock.py

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...