Skip to content

About

C++ tool that detects SSH brute-force attacks by aggregating failed logins per source IP

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

Repository files navigation

SSH Log Analyzer

A C++ tool that reads Linux SSH authentication logs and finds brute-force login attempts by counting failed logins per IP address.

I built this as a first project in log analysis. I'm a CS junior at Bowling Green State University studying cybersecurity.

What it does

Failed SSH logins show up in /var/log/auth.log one line at a time, so an attack doesn't really look like anything until you group the lines by source. This tool does the grouping and sorts by count, so whoever is hammering the server ends up at the top.

It also checks whether the usernames being tried actually exist. Failed password for msingh is probably somebody mistyping their password. Failed password for invalid user root means that account isn't on the system at all, so whoever it is is just guessing names. That second pattern is called user enumeration.

Example

Total lines: 180
Failed logins: 126

203.0.113.42 -> 120 failures (120 to nonexistent accounts)
192.168.1.10 -> 3 failures (0 to nonexistent accounts)
192.168.1.22 -> 2 failures (0 to nonexistent accounts)
10.0.0.15 -> 1 failures (0 to nonexistent accounts)

The first one is the attacker. The other three are normal users who fat-fingered a password.

Running it

python3 generate_log.py
clang++ -std=c++17 -o analyze analyze.cpp
./analyze

Needs Python 3 and a C++17 compiler. Nothing else.

Test data

macOS doesn't have /var/log/auth.log (Apple uses unified logging instead), so I wrote generate_log.py to fake one in the Debian/Ubuntu format.

It makes 180 lines: 60 normal ones spread over a workday with a 10% typo rate, and 120 failed attempts from one IP over about four minutes. Everything gets sorted into time order so the attack is mixed in with the normal traffic instead of sitting in an obvious block at the bottom.

The 10% typo rate is on purpose. Real users mistype passwords, so "flag every failed login" would bury you in false positives. That's why you need a threshold.

How the parsing works

For each line with "Failed password" in it, the tool splits the line into words, finds "from", and takes the next word as the IP. Counts go into a std::map<std::string, int>, then get copied into a vector and sorted descending by count.

Taking the word after "from" works for sshd's format but it's fragile. If a username were literally "from" you'd grab the wrong thing.

What it doesn't do

  • No time window. It counts totals for the whole file, so 120 attempts in four minutes and 120 attempts spread over a week look identical. They're not the same thing.
  • No threshold. It prints everything instead of flagging anything. A real tool would let you set a cutoff and exit nonzero when something crosses it.
  • Doesn't look at successful logins. If an IP fails 100 times and then succeeds, that's the most important thing in the log and this misses it completely. Probably the first thing I'd add.

Stuff I'd add later

  • Sliding time window instead of raw totals
  • Threshold as a command-line flag
  • Detect a success right after a burst of failures
  • CSV output so it could feed into something else

Manjot Singh — github.com/JayM770

About

C++ tool that detects SSH brute-force attacks by aggregating failed logins per source IP

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages