2019-07-15 15:05:04 +02:00
|
|
|
/*
|
|
|
|
* pibs - Create lists of targets under SYN floods for bgp ranking
|
|
|
|
*
|
|
|
|
* Copyright (C) 2019 Gerard Wagener
|
|
|
|
* Copyright (C) 2019 CIRCL Computer Incident Response Center Luxembourg
|
|
|
|
* (SMILE gie).
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
#include <stdio.h>
|
2019-07-15 22:18:14 +02:00
|
|
|
#define __USE_XOPEN
|
|
|
|
#include <time.h>
|
2019-07-15 15:05:04 +02:00
|
|
|
#include "pibs.h"
|
|
|
|
|
|
|
|
void usage(void)
|
|
|
|
{
|
|
|
|
printf("Create lists of targets under SYN floods for BGP Ranking\n");
|
|
|
|
printf("\n");
|
|
|
|
printf("OPTIONS\n");
|
|
|
|
printf(" -h Shows this screen\n");
|
|
|
|
printf(" -r inputfile\n");
|
|
|
|
printf(" Read pcap file from inputfile\n");
|
|
|
|
printf(" -d directory\n");
|
|
|
|
printf(" Root directory where the list should be stored\n");
|
|
|
|
printf("\n");
|
|
|
|
printf("DIRECTORY STRUCTURE\n");
|
|
|
|
printf("<directory>/port/year/month/year-month-day.txt\n");
|
|
|
|
}
|
|
|
|
|
2019-07-15 22:18:14 +02:00
|
|
|
char* create_path(pibs_t* pibs, uint16_t port, uint64_t ts)
|
|
|
|
{
|
|
|
|
struct tm tm;
|
|
|
|
char s[32];
|
|
|
|
char *out;
|
|
|
|
out = calloc(1,FILENAME_MAX);
|
|
|
|
if (out) {
|
|
|
|
snprintf(s,32,"%ld",ts);
|
|
|
|
if (strptime(s,"%s",&tm)){
|
|
|
|
strftime((char*)&s,32,"%Y-%m-%d", &tm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//Something went wrong
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-07-15 16:15:32 +02:00
|
|
|
void frame_to_bgpr(pibs_t* pibs, wtap *wth, uint8_t* eth,
|
|
|
|
struct ip* ipv4, struct tcphdr* tcp)
|
|
|
|
{
|
2019-07-15 22:18:14 +02:00
|
|
|
create_path(pibs, ntohs(tcp->th_sport), wth->rec.ts.secs);
|
2019-07-15 16:15:32 +02:00
|
|
|
}
|
|
|
|
|
2019-07-15 15:05:04 +02:00
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
pibs_t* pibs;
|
|
|
|
int opt;
|
|
|
|
|
|
|
|
|
|
|
|
pibs = init();
|
|
|
|
while ((opt = getopt(argc, argv, "hr:d:")) != -1) {
|
|
|
|
printf("%d\n", opt);
|
|
|
|
switch (opt) {
|
|
|
|
case 'h':
|
|
|
|
usage();
|
|
|
|
break;
|
|
|
|
case 'r':
|
|
|
|
strncpy(pibs->filename, optarg, FILENAME_MAX);
|
2019-07-15 22:39:18 +02:00
|
|
|
pibs->filename[FILENAME_MAX-1] = '\0';
|
2019-07-15 15:05:04 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-15 16:15:32 +02:00
|
|
|
//Set call back function
|
|
|
|
pibs->synseen_callback = &frame_to_bgpr;
|
|
|
|
|
2019-07-15 15:05:04 +02:00
|
|
|
if (pibs->filename[0]) {
|
|
|
|
process_file(pibs);
|
|
|
|
}
|
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|