mirror of
https://github.com/autistic-symposium/sec-pentesting-toolkit.git
synced 2025-05-02 14:56:10 -04:00
ip/icmp scanner
This commit is contained in:
parent
b65ef8b730
commit
4d4b0dcdff
9 changed files with 318 additions and 1 deletions
56
Network_and_802.11/scanner/raw_socket.py
Executable file
56
Network_and_802.11/scanner/raw_socket.py
Executable file
|
@ -0,0 +1,56 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
__author__ = "bt3"
|
||||
|
||||
''' A Basic Sniffer'''
|
||||
|
||||
import socket
|
||||
import os
|
||||
|
||||
# DEFINE CONSTANTS
|
||||
# host to listen
|
||||
HOST = '192.168.1.114'
|
||||
|
||||
|
||||
def main(host):
|
||||
|
||||
OS = os.name
|
||||
|
||||
# create a raw socket, binding to the public interface
|
||||
# windows allow us to sniff all incoming packets regardless of protocol,
|
||||
# whereas Linux forces us to specify we are sniffing ICMP
|
||||
if OS == 'nt':
|
||||
socket_prot = socket.IPPROTO_IP
|
||||
sniffing(host, 1, socket_prot)
|
||||
|
||||
else:
|
||||
socket_prot = socket.IPPROTO_ICMP
|
||||
sniffing(host, 0, socket_prot)
|
||||
|
||||
|
||||
|
||||
def sniffing(host, win, socket_prot):
|
||||
while 1:
|
||||
sniffer = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket_prot)
|
||||
sniffer.bind((host,0))
|
||||
|
||||
# include the IP headers in the captured packets
|
||||
sniffer.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)
|
||||
|
||||
# if windows, it needs to send an IOCTL to set to promiscuous mode
|
||||
# we send IOCTL to the network card driver to enable it
|
||||
# promiscuous mode allows us to sniff all packets that the network card sees
|
||||
# even those not destined to the host
|
||||
if win == 1:
|
||||
sniffer.ioctl(socket.SIO_RCVALL, socket_RCVALL_ON)
|
||||
|
||||
# read in a single packet
|
||||
print sniffer.recvfrom(65565)
|
||||
|
||||
if win == 1:
|
||||
sniffer(host, 0, socket_prot)
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main(HOST)
|
Loading…
Add table
Add a link
Reference in a new issue