Giter VIP home page Giter VIP logo

ssh-honeypot's Introduction

SSH Honeypot

This unfortunately named program listens for incoming ssh connections and logs the IP address, username, and password used by the client. This is a low-interaction honeypot that does not allow malware or attackers to login.

This was originally written to gather rudimentary intelligence on brute force attacks and not meant for production usage.

Nowadays, I mostly use this at attack/defend CTFs paired with sshunt: https://github.com/droberson/sshunt

I set up sshunt to forward tools such as Hydra, Metasploit, and Ncrack to ssh-honeypot and allow OpenSSH clients to connect to ssh normally.

Quickstart

Linux

Make sure headers/development packages are installed for:

  • libssh
  • openssl
  • libjson-c
  • libpcap
apt install libssh-dev libjson-c-dev libpcap-dev libssl-dev

Build and Run

make
ssh-keygen -t rsa -f ./ssh-honeypot.rsa
bin/ssh-honeypot -r ./ssh-honeypot.rsa

OSX (experimental/unsupported)

WARNING: I haven't tested JSON logging, HASSH, or anything really on OSX. MacOS is officially unsupported as I do not own any Macs to test this software with.

Make sure that xcode is up to date.

Install libssh and json-c

brew install libssh json-c

Specify MakefileOSX with make:

make -f MakefileOSX

Docker (experimental)

Please take a look at our Docker documentation.

HASSH

As of version 0.2.0, ssh-honeypot attempts to calculate the HASSH of the client software initiating sessions with ssh-honeypot. In short, you can tell if the client is using OpenSSH, PuTTY, SecureCRT, ...

For more information about HASSH, refer to these links:

Syslog facilities

As of version 0.0.5, this supports logging to syslog. This feature is toggled with the -s flag. It is up to you to configure your syslog facilities appropriately. This logs to LOG_AUTHPRIV which is typically /var/log/auth.log. You may want to modify this to use one of the LOG_LOCAL facilities if you are worried about password leakage.

Dropping Privileges

As of version 0.0.8, you can drop root privileges of this program after binding to a privileged port. You can now run this as nobody on port 22 for example instead of root, but have to initially start it as root:

sudo bin/ssh-honeypot -p 22 -u nobody

Beware that this chowns the logfile to the user specified as well.

Changing the Banner

ssh-honeypot allows you to change the server's banner to blend in with other hosts on your network or mimic a specific device.

List available banners

bin/ssh-honeypot -b

Set banner string

bin/ssh-honeypot -b "my banner string"

Set banner by index

bin/ssh-honeypot -i <banner index>

JSON Logging

The -j CLI flag specifies the path to log results in JSON format. This feature can make log analytics much easier because many languages have robust JSON support.

JSON logs can be sent to a remote host. The -J and -P CLI flags set the host and port to send logs in JSON to, respectively. At this time, logs are transmitted using UDP and not encrypted.

This feature can be useful when running multiple ssh-honeypot instances. Listeners can be created for Splunk and ElasticSearch to ingest these logs and make them searchable.

Systemd Integration

On Linux you can install ssh-honeypot as a Systemd service so that it automatically runs at system startup:

make install
systemctl enable --now ssh-honeypot

Before installing, check ssh-honeypot.service and modify it to run with the options you want.

ssh-honeypot's People

Contributors

droberson avatar eengstrom avatar ibykow avatar link89 avatar santigz avatar sem-hub avatar xzero707 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ssh-honeypot's Issues

Doesn't work on Raspberrypi 2 B

Hi, and thanks a lot for your code.

I've tried to make it run on a Raspberry pi, but it won't.

There is no issue with the compilation, but, when I try to execute it, it give me the help informations.
I've take on my main computer the exact same configuration using scp to transfer from one to the other, recompil' it, and there are no issues on my main.

Configs:
Raspberry Pi 2 B v1.1 with last Stable Raspbian
gcc: gcc (Raspbian 4.9.2-10) 4.9.2

Main : MSI GP62-6qe with Linux Mint 18.1 Cinnamon
gcc: gcc (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609

I've added into your code to check lots of printf() to get me where it goes on the raspberry and which are the values, and what it do is in the main() is going in the default case, even with a parameter.

If you need more informations, contact me, I'll try to figure what is happening, maybe just because of a bad gcc version, idk..

MD5 Error

root@ubuntu~/ssh-honeypot# make
cc -Wall -o bin/ssh-honeypot src/ssh-honeypot.c -lssh -ljson-c -lpcap -lssl -lcrypto
src/ssh-honeypot.c: In function ‘parse_hassh’:
src/ssh-honeypot.c:484:9: warning: ‘MD5_Init’ is deprecated: Since OpenSSL 3.0 [-Wdeprecated-declarations]
484 | MD5_Init(&ctx);
| ^~~~~~~~
In file included from src/ssh-honeypot.c:39:
/usr/include/openssl/md5.h:49:27: note: declared here
49 | OSSL_DEPRECATEDIN_3_0 int MD5_Init(MD5_CTX *c);
| ^~~~~~~~
src/ssh-honeypot.c:485:9: warning: ‘MD5_Update’ is deprecated: Since OpenSSL 3.0 [-Wdeprecated-declarations]
485 | MD5_Update(&ctx, hassh, strlen(hassh));
| ^~~~~~~~~~
In file included from src/ssh-honeypot.c:39:
/usr/include/openssl/md5.h:50:27: note: declared here
50 | OSSL_DEPRECATEDIN_3_0 int MD5_Update(MD5_CTX *c, const void *data, size_t len);
| ^~~~~~~~~~
src/ssh-honeypot.c:486:9: warning: ‘MD5_Final’ is deprecated: Since OpenSSL 3.0 [-Wdeprecated-declarations]
486 | MD5_Final(digest, &ctx);
| ^~~~~~~~~
In file included from src/ssh-honeypot.c:39:
/usr/include/openssl/md5.h:51:27: note: declared here
51 | OSSL_DEPRECATEDIN_3_0 int MD5_Final(unsigned char *md, MD5_CTX *c);
| ^~~~~~~~~

pcap error

Got this error when a client connected and sent no data. This was likely a port scan.

[Thu Mar 3 16:59:13 2022] ERROR: Unable to open ssh pcap file /tmp/ssh-honeypot-369734.pcap: truncated dump file; tried to read 4 file header bytes, only got 0

Source Port in Log

The inclusion of source port in logs is necessary to send abuse reports (via X-ARF). This would be highly beneficial to the project.

ssh-honeypot creates hundreds of forks, consuming all memory

Hi. I’ve been using ssh-honeypot for a few weeks now, and i noticed that the server has a very concerning ram usage. This server is a firewall, and only uses iptables (kernel-space) and ssh-honeypot. Here’s my monitoring graph for the last 7 days:

2020-12-02-110820_grim

The drops in memory consumption are when i restart the ssh-honeypot service (using openrc). Right now, there’s 425 honeypot processes running.

Why is ssh-honeypot behaving like this, and what can be done to prevent crashing my server every 2 days if i don’t stop manually the service?

FATAL: ssh_bind_listen():

~/src/ssh-honeypot(master) » sudo bin/ssh-honeypot -p 22 -u nobody                                          
[Tue May 19 14:50:10 2020] ssh-honeypot 0.1.0 by Daniel Roberson started on port 22. PID 1073190
[Tue May 19 14:50:10 2020] FATAL: ssh_bind_listen(): 
--------------------------------------------------------------------------------------------------------------------------------
~/src/ssh-honeypot(master) » sudo bin/ssh-honeypot -p 2222 -u nobody                                        
[Tue May 19 14:50:13 2020] ssh-honeypot 0.1.0 by Daniel Roberson started on port 2222. PID 1073210
[Tue May 19 14:50:13 2020] FATAL: ssh_bind_listen(): 
--------------------------------------------------------------------------------------------------------------------------------
~/src/ssh-honeypot(master) » sudo bin/ssh-honeypot -p 22222 -u nobody                                       
[Tue May 19 14:50:16 2020] ssh-honeypot 0.1.0 by Daniel Roberson started on port 22222. PID 1073226
[Tue May 19 14:50:16 2020] FATAL: ssh_bind_listen(): 

[feature] allow disabling the file log

I think I can run ssh-honeypot on a readonly filesystem if it didn't need to log. As a workaround, I'm logging to /dev/null right now, but with the way log_entry() is written, writing to console or syslog is in addition to the logfile, which is unfortunate.

JSON log file error

Got this error when dropping permissions. Also does not show the reason for the error:

[Thu Mar 3 16:58:40 2022] FATAL: Unable to open JSON log file:

Help

How do i make it only log the username/passwords? And not the timestamps or ips?

clang is hardcoded in Makefile

Hi.

Is there a reason to hardcode clang as $CC?
I propose to change CC=clang line with CC?=clang. So they can use "CC=gcc make" as a command to build.

Clang needed

Should I install build essentials or just install clang?
I am using Ubuntu 20.04 server so it does not have anything, and I would like to keep it as lightweight as possible.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.