Disculpen los comentarios en ingles... escribi el script para publicarlo en otro lugar pero soy fiel a mi origen, :xD eso fue una excusa... Los puse en ingles y me da peresa traducir. :silbar: :silbar:
Cualquier pregunta o duda, no duden en postearla.
PsData: Fue probado en Linux, se necesitan privilegios para ejecutar.
#! /usr/bin/env python
########################################################################
#Script : WhoPingMe.py #
#Description: Detect if you receive a Ping and make a list with Date. #
#By : LordRNA #
#Date` : Sept 19th-2010 #
#Comments : Tested on Python 2.6.5 #
########################################################################
import socket, datetime
def whopingme(date):
source = '' #To put the IP Source.
header = ["%i"%ord(x) for x in data]
#I made a list of int values for each byte in data variable.
if int(header[20])==8:#If Type(ICMP) is 8, i received a Echo Request.
for x in range(4):#To make a string with the IP Source.
source += str(header[12+x])
if x<3:source +='.'
date = str(datetime.datetime.today())
print date[:len(date)-7]+" ---> "+ str(source)
#I deleted the Miliseconds with [:len(date)-7]
sock = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_ICMP)
#ICMP Protocol on RAW Socket
while 1:
data = sock.recv(21)#I Just want these bytes, IPHeader Lenght + Type(ICMPHeader)
whopingme(data)#Sending data to whopingme() function.
Muestra de la Salida del programa:
rna@rna-laptop:~$ sudo python ./whopingme.py
2010-09-19 00:47:57 ---> 192.168.10.230
2010-09-19 00:47:58 ---> 192.168.10.230
2010-09-19 00:47:59 ---> 192.168.10.230
Edito: Segun me ha dicho Karcrack, LittleHorse y ctlon deberia funcionar en windows con privilegios de administrador.
Muy bien jeje gran code, solo que una pregunta, que pasa si el ping no se hace con icmp?
Saludos
entonces ya no es un ping. :xD... ese es el protocolo especifico para hacer pings
Una pregunta, que no controlo mucho de esto...
Si se cambia el valor de la longitud del paquete y el tipo, se puede detectar la llegada de otro tipo de paquetes, ¿no?
Un saludo ;)
Si se puede.
Muy bueno.
Este puede ser el principio de un gran IDS xD
No tome un punto de vista asi... pero se necesitaria bastante... cuando digo bastante es sumamente bastante informacion.
Segun la documentacion oficial en Windows deberia ir perfectamente :-\
http://docs.python.org/library/socket.html
Cita de: Karcrack en 20 Septiembre 2010, 07:39 AM
Segun la documentacion oficial en Windows deberia ir perfectamente :-\
http://docs.python.org/library/socket.html
Siempre y cuando tengas los privilegios adecuados, caso contrario cualquier operación retornara permiso denegado.
Saludos
tenia entendido que en Windows XP SP2 y posteriores el usuario no podia utilizar Sockets Raw.
se pueden usar pero hay limitaciones, no recuerdo cual eran exactamente ahora mismo pero si se limita el uso.
Entendido
Fuente: http://msdn.microsoft.com/en-us/library/ms740548(VS.85).aspx
Limitations on Raw Sockets
On Windows 7, Windows Server 2008 R2, Windows Vista, and Windows XP with Service Pack 2 (SP2), the ability to send traffic over raw sockets has been restricted in several ways:
1) TCP data cannot be sent over raw sockets.
2) UDP datagrams with an invalid source address cannot be sent over raw sockets. The IP source address for any outgoing UDP datagram must exist on a network interface or the datagram is dropped. This change was made to limit the ability of malicious code to create distributed denial-of-service attacks and limits the ability to send spoofed packets (TCP/IP packets with a forged source IP address).
3) A call to the bind function with a raw socket is not allowed.
Traduzco:
1) No se pueden enviar paquetes TCP.
2) No se pueden enviar paquetes UDP con una direccion de origen invalida.
3) No se puede utilizar bind con un socket RAW.
Posiblemente tenga el mismo requisito de Linux que es que para poder usar Sockets Raw debes de ser el administrador.
mmmmmmm... IDS en python... me gusta la idea de karcrack :P
Muy chulo el código, muy elegante ^.^
Cita de: SnakingMax en 5 Octubre 2010, 23:01 PM
mmmmmmm... IDS en python... me gusta la idea de karcrack :P
Muy chulo el código, muy elegante ^.^
mmmm... la idea fue mia