Personal tools
You are here: Home Downloads faker2.py
Document Actions

faker2.py

by dredd last modified 2006-01-12 03:11 AM

A Python based, threaded tool which for connections on a specified port. Upon connection, it logs the connection attempt, sleeps for a given time, then closes the connection. This is an upgrade to the original Faker.py script.

Click here to get the file

Size 4.6 kB - File type text/x-python

File contents

#! /usr/bin/python
##### faker.py #####
# Copyright (c) 2005, George Bobeck
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, 
# are permitted provided that the following conditions are met:
#
#  * Redistributions of source code must retain the above copyright notice, this 
#    list of conditions and the following disclaimer.
#
#  * Redistributions in binary form must reproduce the above copyright notice, this
#    list of conditions and the following disclaimer in the documentation and/or other
#    materials provided with the distribution.
#
#  * Neither the name of the LOYOLA UNIVERSITY CHICAGO nor the names of its contributors 
#    may be used to endorse or promote products derived from this software without  
#    specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
# SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
# OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#####
#
# To Use:  python faker.py <port>
#
# OR chmod 0700 faker.py so that you can ./faker.py <port>
#
######

import os
import signal
import socket
import sys
import syslog
import thread
from time import *

##### Configurables #####
# Sleep Delay, in Seconds.
delay = 90   

# Message to be sent to offender upon connection.
conn_msg = "Go Away, Lamer!"

# Selected Logging Types
# You can log to 'syslog', 'console', 'file', 'bell', 'none', or any combination of those five

log = ('console', 'file', 'bell')

# You can specify which directory a log file will be created in
filedir = '/root'
#####

arguments = sys.argv[1:]
PORT = int(arguments[0])
HOST = ''           # Symbolic name meaning the local host

times = "Faker.py Started at " + strftime("%d %b %Y %H:%M:%S")

ports = {7:'echo', 9:'discard', 11:'systat', 13:'daytime', 19:'chargen', 20:'ftp-data', 21:'ftp', 22:'ssh', 23:'telnet', 25:'smtp', 37:'time', 42:'nameserver', 53:'DNS', 63:'whois', 67:'bootps', 68:'bootpc', 69:'tftp', 70:'gopher', 79:'finger', 80:'http', 88:'kerberos', 92:'npp', 109:'pop2', 110:'pop3', 113:'auth', 115:'sftp', 119:'nntp', 123:'ntp'} 

# takes a list of strings and returns one large string	    
def stringer(lst): 
	st = ''
	lp = 0
	while lp < len(lst):
		st = st + lst[lp]
		lp = lp + 1
	
	return st

def log_message(message):

	# Sound system bell upon log activity
	if ('bell' in log):
		os.system('echo -n -e "\a"')

	# LOG TO SYSLOG
	if ('syslog' in log):
		syslog.syslog(syslog.LOG_AUTH ,message)
	
	# LOG TO FILE
	if ('file' in log):
		tst = PORT in ports
		if tst:
			fina = filedir + '/' + ports[PORT] + '-faked.log'
		else:
			fina = filedir + '/' + str(PORT) + '-faked.log'
		try:
			# Get data file.
        		input = open(fina , 'r')
        		backup_list = input.readlines()
			out = stringer(backup_list) + message + '\n'
			input = open(fina , 'w')
			input.write(out)
			input.close()
		except:
			# The data file doesn't exist, create it.
        		input = open(fina , 'w')
        		message2 = message + '\n'
			input.write(message2)
			input.close()
	
	# LOG TO CONSOLE
	if ('console' in log):
		print message

	if ('none' in log): 
		pass

def signal_handler(signal, frame):
	timee = "Faker.py Stopped at " + strftime("%d %b %Y %H:%M:%S")
	log_message(timee)
	sys.exit(0)

log_message(times)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))
s.listen(5)

signal.signal(signal.SIGINT, signal_handler)

def handleClient(connection):
	while 1:
		try:
			connection.send(conn_msg)
		#data  = connection.recv(1024)
		#if not data: break
		#connection.send(conn_msg)
		except:
			pass
		sleep(delay)
		break
	connection.close()

def dispatcher():
	while 1:
		time1 = strftime("%d %b %Y %H:%M:%S")
		connection, addr = s.accept()
		thread.start_new(handleClient, (connection,))
		msg = '%s - Connection from %s:%s to localhost:%s'% (time1, addr[0], addr[1],PORT)
		log_message(msg)


dispatcher()
« November 2009 »
Su Mo Tu We Th Fr Sa
1234567
891011121314
15161718192021
22232425262728
2930
 

Powered by Plone CMS, the Open Source Content Management System

This site conforms to the following standards: