Created
December 10, 2011 22:09
-
-
Save omnidan/1456674 to your computer and use it in GitHub Desktop.
HONEYPOT.PY | A simple honeypot written in python.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
""" | |
Copyright (c) 2011, Daniel Bugl | |
All rights reserved. | |
Redistribution and use in source and binary forms, with or without | |
modification, are permitted provided that the following conditions are met: | |
1. Redistributions of source code must retain the above copyright | |
notice, this list of conditions and the following disclaimer. | |
2. 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. | |
3. All advertising materials mentioning features or use of this software | |
must display the following acknowledgement: | |
This product includes software developed by Daniel Bugl. | |
4. Neither the name of Daniel Bugl nor the names | |
of its other contributors may be used to endorse or promote products | |
derived from this software without specific prior written permission. | |
THIS SOFTWARE IS PROVIDED BY Daniel Bugl ''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 <COPYRIGHT HOLDER> 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. | |
""" | |
import time | |
import socket | |
def getInput(): | |
motd = raw_input('MOTD: ') | |
host = raw_input('IP Address: ') | |
while True: | |
try: | |
port = int(raw_input('Port: ')) | |
except TypeError: | |
print 'Error: Invalid port number.' | |
continue | |
else: | |
if (port < 1) or (port > 65535): | |
print 'Error: Invalid port number.' | |
continue | |
else: | |
return (host, port, motd) | |
def writeLog(client, data=''): | |
separator = '='*50 | |
fopen = open('./honey.mmh', 'a') | |
fopen.write('Time: %s\nIP: %s\nPort: %d\nData: %s\n%s\n\n'%(time.ctime(), client[0], client[1], data, separator)) | |
fopen.close() | |
def main(host, port, motd): | |
print 'Starting honeypot!' | |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
s.bind((host, port)) | |
s.listen(100) | |
while True: | |
(insock, address) = s.accept() | |
print 'Connection from: %s:%d' % (address[0], address[1]) | |
try: | |
insock.send('%s\n'%(motd)) | |
data = insock.recv(1024) | |
insock.close() | |
except socket.error, e: | |
writeLog(address) | |
else: | |
writeLog(address, data) | |
if __name__=='__main__': | |
try: | |
stuff = getInput() | |
main(stuff[0], stuff[1], stuff[2]) | |
except KeyboardInterrupt: | |
print 'Bye!' | |
exit(0) | |
except BaseException, e: | |
print 'Error: %s' % (e) | |
exit(1) |
Hey ! How did i run the file please ?
Hi! Thank you very much for your time and for this code. I have to face another little error -> For Example: MOTD: MessageOFTheDAY IP Address: 192.168.100.112 Port: 80 Starting honeypot! Connection from 192.168.100.112:42482 Error: a bytes-like object is required, not 'str' (This happens when i try to access the ip of my laptop from another device - my mobile phone - ).. It breaks in main at the line: try: insock,send('%s\n%(motd)) I am sorry for wasting your time! All the best!
Change line to this to make it a bytes-like object.
insock.send(f"{motd}\n".encode("UTF-8"))
How to run the file please answer ASAP
???
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@florinstefan4197
I'm very new to python and i stumbled upon honeypots and I'm trying to learn it . I wanted to know the entire execution process of this. Did you connect your phone to the laptop hotspot? And how did you get that IP that you enter in?