I've been working on an assignment but have hit the wall at the last steps now.
The task is to automate process of connecting to server, receiving reply, processing the reply - decrypt it, encode and send it back to server.
Here is the main script, i know the data receiving part is not really proper way of doing it but it works for this task:
# -*- encoding: utf-8 -*-
import socket, sys, time
from decryptmsg import decryptmsg
from cleanmsg import cleanmsg
from getkey import getkey
from xor import xorstring
#connection
ip=<ipaddress>
port=<port>
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((ip,port))
while True:
print "[+] START COMMUNICATION WITH SERVER..."
data = sock.recv(8192)
if not data:
print "[-] ei dataa"
print "[+] RECEIVED DATA: " + data
data = cleanmsg(data)
key = str(getkey(data))
print "[+] GOT KEY: " + key
if data != None:
print "[!] PROCESSING DATA: " + data
clear_text = xorstring(data, key, decode=True)
print clear_text
if clear_text == None:
print "[-] NO RESULTS FROM DECRYPTION"
break
else:
print "[+] DECRYPTION SUCCESFULL, SENDING MESSAGE..."
sock.sendall(clear_text)
sock.sendall("\n")
continue
Here are also the function modules:
cleanmsg.py
import re
b64pattern = '(?:[A-Za-z0-9+/]{4}){2,}(?:[A-Za-z0-9+/]{2}[AEIMQUYcgkosw048]=|[A-Za-z0-9+/][AQgw]+={0,2})'
def cleanmsg(data):
if re.search(b64pattern, data):
b64data = re.search(b64pattern,data).group(0).strip()
return b64data
getkey.py
# -*- encoding: utf-8 -*-
import sys, base64, subprocess, os
def getkey(cleaned_data):
key = ""
with open("secret_key.txt", 'w') as file:
try:
file.write(base64.b64decode(cleaned_data + b'==='))
except:
print "[-] B64 DECODE FAILED: "
cmd = 'xortool -m 64 -c 20 secret_key.txt'
process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output = process.stdout.read()
lines = iter(output.splitlines())
for line in lines:
#to see output of xortool
print "[+]" + line
if "possible" in line:
key = next(lines, '')
print "[!] POSSIBLE KEY DETECTED BY XORTOOL: " + key
return key
xor.py
def xorstring(data, key="v", encode=False, decode=False):
from itertools import izip, cycle
import base64
if decode:
data = str(data)
data = base64.b64decode(data + b'===')
xored = ''.join(chr(ord(x) ^ ord(y)) for (x,y) in izip(data, cycle(key)))
if encode:
return base64.encodestring(xored).strip()
return xored
Output from this is following:
[+] START COMMUNICATION WITH SERVER...
[+] RECEIVED DATA: he7Jw8LCw4uH3sjS1YfC38bK18vCh87Uh8bJh9LJwcjV09LJxtPCh8jJwofByNWH3sjS1YfG1cDSysLJ04uFrdTGzsOH78jLysLUi4fTxszOycCH08/Ch9fG18LVh8bJw4fAy8bJxM7JwIfPztSHwt7Ch8PI0MmHztOJh4Xzz87Urc7Uh9PPwofj0snDxtSH1MLXxtXG087IyYfExtTCi4fGycOLh8bUh87Th8/G19fCydSLh+6H0MbUh8LJwMbAwsOtzsmHxMvCxtXOycCH0teH1MjKwofUysbLy4fXyM7J09SHzsmHxMjJycLE087IyYfQztPPh87TiYfzz8Ktz9LUxcbJw4fQxtSHxofTwsLTyNPGy8LVi4fTz8LVwofQxtSHyciHyNPPwtWH0MjKxsmLh8bJw4fTz8KtxMjJw9LE04fEyMrXy8bOycLDh8jBh9DG1IfTz8bTh8/Ch8/Gw4fD1c7B08LDh87J08iH08/Ch8/Gxc7Th8jBrdDOycPOycCH0teHwtHC1d6HysLGy4fF3ofTxszOycCHyNLTh8/O1IfBxsvUwofTwsLTz4fGycOHz9LVy87JwK3Tz8LKh8bTh8/O1IfQzsHCi4fQz87Ez4uH3sjSh9DOy8uHxsvLyNCLh87Uh8nI04fGyYfGxNPOyMmHy87MwsverdPIh8jExNLVh9PIh9PPwofOysbAzsnG087IyYfIwYfTz8KHxtHC1cbAwofU08jV3orTwsvLwtWJh/PGzMKHxq3XzsnEz4fIwYfUydLBwYuH48jE08jVi4fGycOHxsTMycjQy8LDwMKH08/G04fuh8/G0cKH1MTI1cLDh8jRwtWt3sjSh87Jh97I0tWHwt/GytfLwomFkZaWn5SRkZ+XkZWSlZ+Qkp6SlJI=
Enter the SHA-256 hash of the plaintext (in hex):
[+]The most probable key lengths:
[+] 1: 23.3%
[+] 6: 19.4%
[+] 12: 14.2%
[+] 17: 11.0%
[+] 20: 9.8%
[+] 35: 5.4%
[+] 40: 4.6%
[+] 42: 4.7%
[+] 46: 3.9%
[+] 48: 3.6%
[+]Key-length can be 3*n
[+]Key-length can be 4*n
[+]1 possible key(s) of length 1:
[!] POSSIBLE KEY DETECTED BY XORTOOL: \xa7
[+]Found 1 plaintexts with 95.0%+ printable characters
[+]See files filename-key.csv, filename-char_used-perc_printable.csv
[+] GOT KEY: \xa7
[!] PROCESSING DATA: he7Jw8LCw4uH3sjS1YfC38bK18vCh87Uh8bJh9LJwcjV09LJxtPCh8jJwofByNWH3sjS1YfG1cDSysLJ04uFrdTGzsOH78jLysLUi4fTxszOycCH08/Ch9fG18LVh8bJw4fAy8bJxM7JwIfPztSHwt7Ch8PI0MmHztOJh4Xzz87Urc7Uh9PPwofj0snDxtSH1MLXxtXG087IyYfExtTCi4fGycOLh8bUh87Th8/G19fCydSLh+6H0MbUh8LJwMbAwsOtzsmHxMvCxtXOycCH0teH1MjKwofUysbLy4fXyM7J09SHzsmHxMjJycLE087IyYfQztPPh87TiYfzz8Ktz9LUxcbJw4fQxtSHxofTwsLTyNPGy8LVi4fTz8LVwofQxtSHyciHyNPPwtWH0MjKxsmLh8bJw4fTz8KtxMjJw9LE04fEyMrXy8bOycLDh8jBh9DG1IfTz8bTh8/Ch8/Gw4fD1c7B08LDh87J08iH08/Ch8/Gxc7Th8jBrdDOycPOycCH0teHwtHC1d6HysLGy4fF3ofTxszOycCHyNLTh8/O1IfBxsvUwofTwsLTz4fGycOHz9LVy87JwK3Tz8LKh8bTh8/O1IfQzsHCi4fQz87Ez4uH3sjSh9DOy8uHxsvLyNCLh87Uh8nI04fGyYfGxNPOyMmHy87MwsverdPIh8jExNLVh9PIh9PPwofOysbAzsnG087IyYfIwYfTz8KHxtHC1cbAwofU08jV3orTwsvLwtWJh/PGzMKHxq3XzsnEz4fIwYfUydLBwYuH48jE08jVi4fGycOHxsTMycjQy8LDwMKH08/G04fuh8/G0cKH1MTI1cLDh8jRwtWt3sjSh87Jh97I0tWHwt/GytfLwomFkZaWn5SRkZ+XkZWSlZ+Qkp6SlJI=
��������ꂰ�✙��ь����綫����ړ��ɒ�������۹�✅���������������ϝ����������ꏾ��қ��ԙ������ꚱ��ې��ߕ������Ꞧ��ؓज�㲶�����կ㜈��������綹����݈���������������ݏ���������������˝��ْ�������ٝ��қ�����������ݐ��̓�������ۼ��ҙ��Փ������꒫������ԉ�����������ȓ������ꏷ�������������������ѝ�朝�����������ɟ��ߓ�����������������������꓾��؎��ș������ꏷ��ԝ���������������Ɍ��ʙ�������۽��ȝ��қ�����������Џ��ș�������۷��Е����������ꓶ��˕����������ꂰ��˕�������븶������������������������㥜��������۫������ە������ꔹ��ԙ��ʙ�����徔���ș��َ��������ն�ҟ��Ӛ�������ۛ��ȓ�朝�����������؛��Ȕ���մ������ߓ���������漏���������������������Ĥ��ħ�����������
[+] DECRYPTION SUCCESFULL, SENDING MESSAGE...
[+] START COMMUNICATION WITH SERVER...
Traceback (most recent call last):
File "challenge.py", line 19, in <module>
data = sock.recv(8192)
socket.error: [Errno 104] Connection reset by peer
So the data is not properly decrypted.
However, if i take the output from above and insert it to the test script below:
# -*- encoding: utf-8 -*-
import sys
from xor import xorstring
key = '\xa7'
string = 'he7Jw8LCw4uH3sjS1YfC38bK18vCh87Uh8bJh9LJwcjV09LJxtPCh8jJwofByNWH3sjS1YfG1cDSysLJ04uFrdTGzsOH78jLysLUi4fTxszOycCH08/Ch9fG18LVh8bJw4fAy8bJxM7JwIfPztSHwt7Ch8PI0MmHztOJh4Xzz$
dekoodattu = xorstring(string, key, decode=True)
print dekoodattu
and run the script, the output is correct:
root#45s:~# python test.py
"Indeed, your example is an unfortunate one for your argument,"
said Holmes, taking the paper and glancing his eye down it. "This
is the Dundas separation case, and, as it happens, I was engaged
in clearing up some small points in connection with it. The
husband was a teetotaler, there was no other woman, and the
conduct complained of was that he had drifted into the habit of
winding up every meal by taking out his false teeth and hurling
them at his wife, which, you will allow, is not an action likely
to occur to the imagination of the average story-teller. Take a
pinch of snuff, Doctor, and acknowledge that I have scored over
you in your example."61183668062528759535
I'm totally lost here that why is the script working on it's own but in the main script the decryption is mangled - i guess something is added or removed from either the key or string in some stage but can't figure out where or why.
Any help is extremely appreciated :)
Related
I am connecting to a pre-configured server that serves four different file formats with different sizes. Each file is appended with the file size...
Example: lighthouse.jpg
561276ÿØÿà JFIF ` ` ÿî Adobe
The "561276" is the file size and needs to be pruned before saving the file.
Example: randomText.txt
45711111111111111111111111111111111111111111111111111111111
222222222222222222222222222222222222222222222222222222222
33333333333333333333333333333333333333333333333333
44444444444444444444444444444444444444444444444444444444
66666666666666666666
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
cvccccccccccccccccccccccccccccccccccccccccccccccc
ddddddddddddddddddddddddddddddddddddddddddddddddddd
The "457" is the file size and needs to be pruned before saving the file.
Some files have a size that is only 3-digits long. Some have a file size that is 6-digits long (as seen here). I want to make my code size-agnostic; regardless of how many digits is in the size.
I've tried using:
while len(buf) < 4:
buf += sock.recv(4 - len(buf))
size = struct.unpack('!i', buf)
but this only prunes the first four digits.
AND
I've tried using
len = sock.recv(4)
data = sock.recv(len)
but once again... only prunes the first four digits
Here is what I have so far:
def get_size():
buf = ''
while len(buf) < 4:
buf += sock.recv(4 - len(buf))
size = struct.unpack('!i', buf)
print "[*] Receiving %s bytes" % size
def download_pic():
size = get_size()
fname = 'tst.jpg'
with open(fname, 'wb') as img:
while True:
data = sock.recv(1024)
if not data:
break
img.write(data)
print '[*] {0} received!'.format(fname)
def main():
doconnectionstuffandprinttoconsole() #establishes connection
answer = input("[>] Your Selection: ")
sock.send(str(answer))
if answer == 2:
download_pic()
sock.close()
Any help in pruning the size from the file(s) would be greatly appreciated!
Jason Harper's suggestion (#jasonharper) got me thinking. When I ran repr(data) on the chunks from randomText.txt, I saw that it had a break in it that looked like...
'457''1111111111111111111111...
The server was attempting to send two different chunks (one at at time) but it kept getting merged into one chunk. So, I increased my sock.recv(64) up to sock.recv(256). And for some reason, it send two chunks!
'457'
'111111111...' [truncated]
NEW AND IMPROVED CODE!
import socket
import sys
import struct
import os
user1 = {'user1': 91827364}
user2 = {'user2': 19283746}
user3 = {'user3': 46372819}
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(('127.0.0.1', 2058))
def print_data():
data_rcv = sock.recv(1024)
print "[-] {0}".format(data_rcv)
def download_file(format):
fname = 'download'
fullname = fname + '.' + format
try:
with open(fullname, 'wb') as txt:
len = sock.recv(256)
while True:
data = sock.recv(int(len))
if not data:
break
txt.write(data)
print("[*] {0} successfully downloaded with a length of {1} characters!".format(fullname, len))
except Exception:
print("[!] Error receiving file. Please try again.")
def connect():
print("[*] Sending Length")
sock.send("5")
my_struct = struct.pack('5s i', 'user1', 91827364)
print("[*] Sending User1 Struct")
sock.send(my_struct)
print_data()
def main():
print_data()
connect()
print_data()
answer = input("[>] Your Selection: ")
sock.send(str(answer))
if answer == 2: # Option to download Lighthouse.jpg
download_file("jpg")
elif answer == 4: # Option to download randomText.txt
download_file("txt")
sock.close()
if __name__ == "__main__":
main()
MY OUTPUT
[-] Please enter credentials
[*] Sending Length
[*] Sending User1 Struct
[-] Authenticated
[-] Choose a file to retrieve from the following list (enter the number):
1. photo.png
2. Lighthouse.jpg
3. npp.6.8.5.Installer.exe
4. randomText.txt
[>] Your Selection: 2
[*] download.jpg successfully downloaded with a length of 561276 characters!
What i want to achieve would be reading the IP/Domain from the TXT file and executing an OS import command then adding the IP/Domain when pinging.
However the problem is that for some reason it's placing a period at the end of the IP/Domain that it read from the TXT file, resulting in an invalid request when pining (the code works the only problem would be the period at the end)
for example: when the pinging line executes on the compiler it's telling me "bad parameters google.com." however on the txt file it self there is only one period which is the one for the .com it self.
def scanlist():
ipopen = open("IPlist.txt")
#Opens the IPlist.txt file and strips each of the lines so that we can read individually.
with open("IPlist.txt", "r+") as ips_file:
ips = [ip.strip() for ip in ips_file.readlines()]
#Read each line from the IPlist.txt file
with open("IPlist.txt", "r") as available_ips_file:
for ip in ips:
#Pings each line from the IPlist.txt file
response = os.system('ping -a 1 {}'.format(ip))
if response == 0: # 512/DOWN value - 0/UP value
# Up
print("- Ip Address:", ip, 'is up!')
elif response == 512:
#down
print("- IP Address:", ip, 'is down!')
else:
#other error
print("- Bad parameters or other error!")
For the entire code visit the github: https://github.com/Hontiris1/IPPing/blob/master/Ping.py
the issue was in the paramter you were passing to the ping the 1 after -a is not a valid parameter
import os
def scanlist():
#Opens the IPlist.txt file and strips each of the lines so that we can read individually.
with open("IPlist.txt") as ips_file:
ips = list(map(str.strip,ips_file.readlines()))
#Read each line from the IPlist.txt file
for ip in ips:
#Pings each line from the IPlist.txt file
response = os.system('ping {} -a -n 1'.format(ip)) # to send only one request
if response == 0: # 512/DOWN value - 0/UP value
# Up
print("- Ip Address:", ip, 'is up!')
elif response == 1: # if it's time out
#down
print("- IP Address:", ip, 'is down!')
else:
#other error
print("- Bad parameters or other error!")
scanlist()
output
Pinging 8.8.8.8 with 32 bytes of data:
Reply from 8.8.8.8: bytes=32 time=55ms TTL=56
Ping statistics for 8.8.8.8:
Packets: Sent = 1, Received = 1, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 55ms, Maximum = 55ms, Average = 55ms
- Ip Address: 8.8.8.8 is up!
Pinging stackoverflowll.com [218.93.250.18] with 32 bytes of data:
Request timed out.
Ping statistics for 218.93.250.18:
Packets: Sent = 1, Received = 0, Lost = 1 (100% loss),
- IP Address: stackoverflowll.com is down!
I've been editing this port scanner for an information security project.
The code works but throws errors (Pycharm Edu) on lines 63 and 34 in that order.
The error message for line 63 is: 'line 63, in
checkhost(target). I've looked at this and can't see why this would throw an error specifically as it is defined on line 34.
The error message for line 34 is: 'NameError: global name 'conf' is not defined'. It's not clear why this is a problem either.
Any help is much appreciated.
The Python code environment is Python 2.7.10
#! /usr/bin/python
from logging import getLogger, ERROR # Import Logging Things
getLogger("scapy.runtime").setLevel(ERROR) # Get Rid if IPv6 Warning
import scapy
import sys
from datetime import datetime # Other stuff
from time import strftime
try:
target = raw_input("[*] Enter Target IP Address: ")
min_port = raw_input("[*] Enter Minumum Port Number: ")
max_port = raw_input("[*] Enter Maximum Port Number: ")
try:
if int(min_port) >= 0 and int(max_port) >= 0 and
int(max_port) >= int(min_port): # Test for valid range of ports
pass
else: # If range didn't raise error, but didn't meet criteria
print "\n[!] Invalid Range of Ports"
print "[!] Exiting..."
sys.exit(1)
except Exception: # If input range raises an error
print "\n[!] Invalid Range of Ports"
print "[!] Exiting..."
sys.exit(1)
except KeyboardInterrupt: # In case the user wants to quit
print "\n[*] User Requested Shutdown..."
print "[*] Exiting..."
sys.exit(1)
ports = range(int(min_port), int(max_port)+1)
start_clock = datetime.now() # Start clock for scan time
SYNACK = 0x12 # Set flag values for later reference
RSTACK = 0x14
def checkhost(target): # Function to check if target is up
conf.verb = 0 # Hide output
try:
ping = sr1(IP(dst = ip)/ICMP()) # Ping the target
print "\n[*] Target is Up, Beginning Scan..."
except Exception: # If ping fails
print "\n[!] Couldn't Resolve Target"
print "[!] Exiting..."
sys.exit(1)
def scanport(port): # Function to scan a given port
try:
srcport = RandShort() # Generate Port Number
conf.verb = 0 # Hide output
SYNACKpkt = sr1(IP(dst = target)/TCP(sport = srcport,
dport = port,flags = "S"))
pktflags = SYNACKpkt.getlayer(TCP).flags
if pktflags == SYNACK: # Cross reference Flags
return True # If open, return true
else:
return False
RSTpkt = IP(dst = target)/TCP(sport = srcport, dport = port,
flags = "R") # Construct RST packet send(RSTpkt)
except KeyboardInterrupt: # In case the user needs to quit
RSTpkt = IP(dst = target)/TCP(sport = srcport, dport = port,
flags = "R") send(RSTpkt)
print "\n[*] User Requested Shutdown..."
print "[*] Exiting..."
sys.exit(1)
checkhost(ip) # Run checkhost() function from earlier
print "[*] Scanning Started at " + strftime("%H:%M:%S") + "!\n"
for port in ports: # Iterate through range of ports
status = scanport(port) # Feed each port into scanning function
if status == True: # Test result
print "Port " + str(port) + ": Open" # Print status
stop_clock = datetime.now() # Stop clock for scan time
total_time = stop_clock - start_clock # Calculate scan time
print "\n[*] Scanning Finished!" # Confirm scan stop
print "[*] Total Scan Duration: " + str(total_time) # Print scan time
The problem is with your import statement, it should
be:
>>> import scapy
>>> from scapy.all import conf
>>> conf.verb = 0
or even better to get rid of possible similar errors in the future
just import scapy as:
>>> from scapy.all import *
>>> conf.verb = 0
Now it should work fine.
I'm not an expert in programming so i googled a lot to get this script to work. It listens on the serial interface ans is searching for 3 values (temperature, humidity and battery level). If it finds one of zhem it saves it to a text file and checks if the value is above or under a certain level. I f this is the case it sends an e-mail to warn.
My problem is that it uses constatntly about 99% of cpu power...
Can you help me to limit the CPU usage to a minimum.
Thanks
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import serial
import time
import sys
import smtplib
from time import sleep
def mail(kind, how, value, unit):
fromaddr = 'sender#domain.com'
toaddrs = 'recipient#domain.com'
msg = "\r\n".join([
"From: sender",
"To: recipient",
"Subject: Warning",
"",
"The " + str(kind) + " is too " + str(how) + ". It is " + str(value) + str(unit)
])
username = 'user'
password = 'password'
server = smtplib.SMTP('server:port')
server.ehlo()
server.starttls()
server.login(username,password)
server.sendmail(fromaddr, toaddrs, msg)
server.quit()
def main():
port = '/dev/ttyAMA0'
baud = 9600
ser = serial.Serial(port=port, baudrate=baud)
sleep(0.2)
while True:
while ser.inWaiting():
# read a single character
char = ser.read()
# check we have the start of a LLAP message
if char == 'a':
# start building the full llap message by adding the 'a' we have
llapMsg = 'a'
# read in the next 11 characters form the serial buffer
# into the llap message
llapMsg += ser.read(11)
if "TMPB" in llapMsg:
TMPB = llapMsg[7:]
with open("TMPB.txt", "w") as text_file:
text_file.write(TMPB)
if float(TMPB) >= 19:
mail("temperature", "high", TMPB, "°C")
elif float(TMPB) <= 15:
mail("temperature", "low", TMPB, "°C")
else:
pass
elif "HUMB" in llapMsg:
HUMB = llapMsg[7:]
with open("HUMB.txt", "w") as text_file:
text_file.write(HUMB)
if float(HUMB) >= 80:
mail("humidity", "high", HUMB, "%")
elif float(HUMB) <= 70:
mail("humidity", "low", HUMB, "%")
else:
pass
elif "BATT" in llapMsg:
BATT = llapMsg[7:11]
with open("BATT.txt", "w") as text_file:
text_file.write(BATT)
if float(BATT) < 1:
mail("battery level", "low", BATT, "V")
else:
pass
sleep(0.2)
if __name__ == "__main__":
main()
I solved the question myself.
The while ser.inWaiting(): loop was causing the heavy cpu load.
I removed it and corrected the indentation and it works great with a few % cpu load.
Thanks for your hints, it helped me solving the problem.
I'm using the below script for injecting an ARP packet request. When I keep the source (MAC and IP) as my machine, I can happily see the packets in the wire and receive ARP replies however on changing the source to a different machine in the LAN, the ARP requests don't get back the ARP replies.
I am dicey if the RAW sockets can only frame up an ARP request for the base machine or am I going wrong somewhere ?
Below is the code ...
#!/usr/bin/python
import sys
import socket
import binascii
import struct
from itertools import chain
try:
iFace = raw_input("Enter the interface using which the Injection needs to be done ...\n")
rawSocket = socket.socket(socket.PF_PACKET, socket.SOCK_RAW,socket.htons(0x0800))
rawSocket.bind((iFace, socket.htons(0x0800)))
print "Raw Socket got created .... with the Ethernet Protocol Id : 0x0806 at interface %s"%str(iFace)
except:
print "Something unexpected happened during the Program execution."
else:
def checkMac(mac):
if len(mac.split(":")) != 6:
print "The MAC is in correct. It should be in Hexadecimal Format with each byte separated with colon...\n"
sys.exit(0)
else:
macList = mac.split(":")
macLen = len(macList)
return tuple ([int(macList[index],16) for index in range(macLen)])
def checkIp(ip):
ipList = ip.split(".")
ipLen = len(ipList)
return int( "".join( [ "{:02X}".format(int(ele)) for ele in ipList ] ), 16 )
dMac = raw_input("Enter the Destination MAC .. hexadecimal charaters separated with ':' \n")
# dMac = "0X:XX:XX:XX:XX:4X"
dMacTup = checkMac(dMac)
# sMac = raw_input("Enter the Source MAC .. hexadecimal charaters separated with ':' \n")
sMac = "XX:XX:XX:XX:XX:XX"
sMacTup = checkMac(sMac)
type = 0x0806
# Creating an Ethernet Packet .... using dMac, sMac, type
etherPack = struct.pack ("!6B6BH",*tuple(chain(dMacTup,sMacTup,[type])))
# Creating an ARP Packet .... now
hardwareType = 0x0001
protocolType = 0x0800
hln = 0x06
pln = 0x04
op = 0x0001
# srcIp = raw_input("Enter the Source IP ':' \n")
srcIp = "10.0.2.216"
intSrcIp = checkIp(srcIp)
destIp = raw_input("Enter the Destination IP .. \n")
# destIp = "10.0.2.1"
intDestIp = checkIp(destIp)
arpPack = struct.pack("!HHBBH6BI6BI", *tuple(chain( [hardwareType,protocolType,hln,pln,op], sMacTup,[intSrcIp], dMacTup,[intDestIp] )))
# Framing the final Packet
finalPack = etherPack + arpPack
for i in range(50):
rawSocket.send(finalPack + "Hacker in the wires ...")
print "Sending Packet %d"%i
finally:
print "Closing the created Raw Socket ..."
rawSocket.close()