Skip to content

vibheksoni/libssh-c-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

libssh C SSH Server Example

A lightweight SSH honeypot/server implementation written in C using the libssh library. This project demonstrates low-level SSH server development for security research, network testing, and educational purposes.

Features

  • Native C implementation for performance
  • Multi-threaded connection handling with pthreads
  • Password-based authentication
  • Interactive shell session support
  • Custom command handling
  • Non-blocking channel I/O
  • Clean session management and cleanup

Requirements

  • GCC or compatible C compiler
  • libssh development libraries
  • pthread library (usually included with GCC)
  • Linux/Unix environment (or WSL on Windows)

Installation

  1. Clone the repository:
git clone https://github.com/vibheksoni/libssh-c-example.git
cd libssh-c-example
  1. Install libssh development libraries:

Ubuntu/Debian:

sudo apt-get install libssh-dev

Fedora/RHEL:

sudo dnf install libssh-devel

macOS:

brew install libssh
  1. Generate SSH host key:
mkdir ssh_keys
ssh-keygen -t rsa -b 2048 -f ssh_keys/rsa.key -N ""

Compilation

Compile the project using GCC:

gcc -o ssh_server main.c ssh.c user.c -lssh -lpthread

Or use the provided Makefile if available:

make

Usage

Run the SSH server with host, key path, and port:

./ssh_server 0.0.0.0 ./ssh_keys/rsa.key 2222

Connect using any SSH client:

ssh admin@localhost -p 2222

Default credentials:

  • Username: admin
  • Password: admin

Project Structure

libssh-c-example/
├── main.c              # Entry point and argument parsing
├── ssh.c               # SSH server configuration and connection handler
├── user.c              # User authentication and session management
├── headers/
│   ├── ssh.h          # SSH server function declarations
│   └── user.h         # User session function declarations
└── ssh_keys/          # Directory for SSH host keys
    └── rsa.key        # RSA private key for the server

Key Components

ssh.c

  • SshConfig(): Initialize server configuration
  • SshInit(): Set up SSH bind options
  • SshStart(): Start listening for connections
  • SshConnectionHandler(): Accept and handle incoming connections

user.c

  • UserCreate(): Create new user session
  • UserAuth(): Authenticate user credentials
  • UserSessionInit(): Initialize SSH session and channel
  • ClientHandler(): Main client interaction loop
  • SshPrintf(): Write formatted output to SSH channel
  • SshRead(): Read input from SSH channel

Security Notice

This is a honeypot/research tool intended for:

  • Security research and testing
  • Educational purposes
  • Controlled lab environments
  • Network security analysis

Do not expose this server to the public internet without proper security measures.

License

MIT License - See LICENSE file for details

About

Lightweight SSH honeypot/server implementation in C using libssh library for security research and network testing

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors