mirror of
https://github.com/cowrie/cowrie.git
synced 2025-07-01 18:07:27 -04:00
support for ping -c
This commit is contained in:
@ -5,6 +5,7 @@ import re
|
|||||||
import random
|
import random
|
||||||
import hashlib
|
import hashlib
|
||||||
import socket
|
import socket
|
||||||
|
import getopt
|
||||||
|
|
||||||
from twisted.internet import reactor
|
from twisted.internet import reactor
|
||||||
|
|
||||||
@ -23,10 +24,28 @@ class command_ping(HoneyPotCommand):
|
|||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
self.host = None
|
self.host = None
|
||||||
for arg in self.args:
|
self.max = 0
|
||||||
if not arg.startswith('-'):
|
self.running = False
|
||||||
self.host = arg.strip()
|
|
||||||
break
|
try:
|
||||||
|
optlist, args = getopt.getopt(self.args, "c:")
|
||||||
|
except getopt.GetoptError as err:
|
||||||
|
self.writeln('ping: %s' % err )
|
||||||
|
self.exit()
|
||||||
|
return
|
||||||
|
|
||||||
|
for opt in optlist:
|
||||||
|
if opt[0] == '-c':
|
||||||
|
try:
|
||||||
|
self.max = int(opt[1])
|
||||||
|
except:
|
||||||
|
self.max = 0
|
||||||
|
if self.max == 0:
|
||||||
|
self.writeln('ping: bad number of packets to transmit.')
|
||||||
|
self.exit()
|
||||||
|
return
|
||||||
|
|
||||||
|
self.host = args[0].strip()
|
||||||
|
|
||||||
if not self.host:
|
if not self.host:
|
||||||
for l in (
|
for l in (
|
||||||
@ -50,6 +69,7 @@ class command_ping(HoneyPotCommand):
|
|||||||
self.ip = '.'.join([str(int(x, 16)) for x in
|
self.ip = '.'.join([str(int(x, 16)) for x in
|
||||||
(s[0:2], s[2:4], s[4:6], s[6:8])])
|
(s[0:2], s[2:4], s[4:6], s[6:8])])
|
||||||
|
|
||||||
|
self.running = True
|
||||||
self.writeln('PING %s (%s) 56(84) bytes of data.' % \
|
self.writeln('PING %s (%s) 56(84) bytes of data.' % \
|
||||||
(self.host, self.ip))
|
(self.host, self.ip))
|
||||||
self.scheduled = reactor.callLater(0.2, self.showreply)
|
self.scheduled = reactor.callLater(0.2, self.showreply)
|
||||||
@ -60,14 +80,29 @@ class command_ping(HoneyPotCommand):
|
|||||||
self.writeln(
|
self.writeln(
|
||||||
'64 bytes from %s (%s): icmp_seq=%d ttl=50 time=%.1f ms' % \
|
'64 bytes from %s (%s): icmp_seq=%d ttl=50 time=%.1f ms' % \
|
||||||
(self.host, self.ip, self.count + 1, ms))
|
(self.host, self.ip, self.count + 1, ms))
|
||||||
|
self.writeln( "self.max: %d, self.count: %d" % (self.max,self.count))
|
||||||
self.count += 1
|
self.count += 1
|
||||||
self.scheduled = reactor.callLater(1, self.showreply)
|
if self.count == self.max:
|
||||||
|
self.running = False
|
||||||
|
self.writeln('')
|
||||||
|
self.printstatistics()
|
||||||
|
self.exit()
|
||||||
|
else:
|
||||||
|
self.scheduled = reactor.callLater(1, self.showreply)
|
||||||
|
|
||||||
def handle_CTRL_C(self):
|
def printstatistics(self):
|
||||||
self.scheduled.cancel()
|
|
||||||
self.writeln('--- %s ping statistics ---' % self.host)
|
self.writeln('--- %s ping statistics ---' % self.host)
|
||||||
self.writeln('%d packets transmitted, %d received, 0%% packet loss, time 907ms' % \
|
self.writeln('%d packets transmitted, %d received, 0%% packet loss, time 907ms' % \
|
||||||
(self.count, self.count))
|
(self.count, self.count))
|
||||||
self.writeln('rtt min/avg/max/mdev = 48.264/50.352/52.441/2.100 ms')
|
self.writeln('rtt min/avg/max/mdev = 48.264/50.352/52.441/2.100 ms')
|
||||||
self.exit()
|
|
||||||
|
def handle_CTRL_C(self):
|
||||||
|
if self.running == False:
|
||||||
|
return HoneyPotCommand.handle_CTRL_C(self)
|
||||||
|
else:
|
||||||
|
self.writeln('^C')
|
||||||
|
self.scheduled.cancel()
|
||||||
|
self.printstatistics()
|
||||||
|
self.exit()
|
||||||
|
|
||||||
commands['/bin/ping'] = command_ping
|
commands['/bin/ping'] = command_ping
|
||||||
|
|||||||
Reference in New Issue
Block a user