Skip to content

Add sheep database support #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
config.pl
9 changes: 9 additions & 0 deletions config.pl.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
dbname => "",
driver => "",
host => "",
userid => "",
passwd => "",
# Wouldn't this be ironic?
option => "sslmode=require"
}
2 changes: 1 addition & 1 deletion stupid_ettercap.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash

while true; do
ettercap -i eth0 -Tzqu | ./wall_of_sheep.pl
ettercap -i $1 -Tzqu | ./wall_of_sheep.pl $1
done
34 changes: 34 additions & 0 deletions wall_of_sheep.pl
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/usr/bin/perl

use DBI;
use strict;
use warnings;
use 5.010;
Expand All @@ -12,6 +14,35 @@

my (%idiots, @whitelist);

my $iface = $ARGV[0];
shift;

my $config = do("config.pl");
my $dsn = "DBI:$config->{driver}:dbname=$config->{dbname};host=$config->{host};$config->{option}";

my $dbh = DBI->connect($dsn, $config->{userid}, $config->{passwd}, { RaiseError => 1 })
or die $DBI::errstr;

my $db_create_table = qq(
CREATE TABLE IF NOT EXISTS entries (
ID SERIAL PRIMARY KEY NOT NULL,
IPADDR TEXT NOT NULL,
IFACE TEXT NOT NULL,
HOSTNAME TEXT NOT NULL,
PROTOCOL TEXT NOT NULL,
USERNAME TEXT NOT NULL,
PASSWORD TEXT NOT NULL
););

my $db_add_entry = $dbh->prepare(qq(
INSERT INTO entries
(IPADDR, IFACE, HOSTNAME, PROTOCOL, USERNAME, PASSWORD)
VALUES
(?, ?, ?, ?, ?, ?);
));

my $rv = $dbh->do($db_create_table) or die $DBI::errstr;

# Newline delimited list of hostnames
if ( -f WHITELIST_FILE) {
open (my $fh, WHITELIST_FILE);
Expand Down Expand Up @@ -69,6 +100,9 @@
print pack("A10 A16 A29 A17 A".PASS_LENGTH, $protocol, $ip, $hostname, $user, $pass);
print "\n";
print color("reset");

# also update the db
$rv = $db_add_entry->execute($ip, $iface, $hostname, $protocol, $user, $pass) or die $DBI::errstr;
}
}

Expand Down