Skip to content

Commit 06dfded

Browse files
authored
Add nua scanner
1 parent 643e9f5 commit 06dfded

1 file changed

Lines changed: 263 additions & 0 deletions

File tree

nns.c

Lines changed: 263 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,263 @@
1+
/* Attenction: p0rk program detected! ***WARNING*** ***WARNING*** ***WARN.........0ink!*/
2+
3+
#include <stdio.h>
4+
#include <stdlib.h>
5+
#include <sys/types.h>
6+
#include <sys/socket.h>
7+
#include <netdb.h>
8+
#include <arpa/inet.h>
9+
#include <netinet/in.h>
10+
#include <pwd.h>
11+
#include <string.h>
12+
13+
int nscan (unsigned long padip, int nuastart,int nuaend,int ports);
14+
void external_login(unsigned long padip,char login[25],char password[25]);
15+
unsigned long resolve(char *host);
16+
17+
unsigned long resolve(char *host)
18+
{
19+
struct hostent *he;
20+
long i;
21+
22+
23+
if((i=inet_addr(host))<0) // E' un ip gia' di suo oppure no?
24+
/* Zi' lo e', proviamo a risolverlo */
25+
if((he=gethostbyname(host))==NULL)
26+
return(0); // nada, no resolve
27+
else
28+
return(*(unsigned long *)he->h_addr); // ok ekko l'ip
29+
30+
return(i); // ritorno gia' l'ip
31+
}
32+
33+
char *logfile;
34+
int fdr;
35+
int fdw;
36+
char buf[1024];
37+
int s;
38+
int dnic,zbn;
39+
void main(int argc,char **argv)
40+
{
41+
42+
int ports;
43+
long int nuastart,nuaend,nuadiff;
44+
char *ph;
45+
unsigned long padip;
46+
printf("NaiL NUA Scanner Inet->Cisco/pad v1.00 - nobody everywhere\n");
47+
/* Meno di 5 parametri ? help!:) */
48+
if(argc<6) {
49+
printf("Use: nns <hostname> <number of free x25 channels> <dnic or 0> <starting NUA> <\n");
50+
printf("Final NUA> [logfile]");
51+
exit(200);
52+
}
53+
/* Ne abibamo addirittuera 6 (il logfile) ? akkiappiamolo in una var a pparte*/
54+
logfile=malloc(400);
55+
if(argc>6) {
56+
strcpy(logfile,argv[6]);
57+
printf("Using logfile: %s\n",logfile);
58+
}
59+
else
60+
logfile=NULL;
61+
/* Atoi = da stringa a intero*/
62+
63+
ports=atoi(argv[2]);
64+
zbn = 1;
65+
66+
if(!strcmp(argv[3],"0")) zbn =0;
67+
dnic = atoi(argv[3]);
68+
69+
nuastart = atoi(argv[4]);
70+
nuaend = atoi(argv[5]);
71+
if(nuaend<nuastart) {
72+
/* Qui li scambio */
73+
nuadiff = nuaend;
74+
nuaend=nuastart;
75+
nuastart=nuadiff;
76+
}
77+
nuadiff = nuaend - nuastart;
78+
if( nuadiff < 0 || nuadiff > 65530 )
79+
{
80+
printf("Error in NUA difference, please use a start > than a final \n");
81+
printf("And don't exceed 65530 nuas at a time\n");
82+
exit(201);
83+
}
84+
/* Mi akkiappo l'hostnamukolo e lo rizolvo*/
85+
strcpy(ph,argv[1]);
86+
87+
printf("Resolving pad hostname ...\n");
88+
padip=resolve(ph);
89+
if(padip==0) {
90+
printf("Unable to resolve pad hostname\n");
91+
exit(202);
92+
}
93+
/* Rikiamo la procedura di zkan */
94+
ports = nscan(padip,nuastart,nuaend,ports);
95+
fprintf(stderr,"Totally found nuas: %d\nExiting.\n",ports);
96+
exit(0);
97+
}
98+
99+
100+
101+
int nscan (unsigned long padip, int nuastart,int nuaend,int ports)
102+
{
103+
/* This program is made to pad throught a cisco right now */
104+
/* So we will ask for a login and a password */
105+
char login[25];
106+
char password[25];
107+
char prmpt[50];
108+
int i,fn;
109+
/* Kiedo al tizio davanti al pc ke si fa le pippe mentali kon sto progghie
110+
di darmi login e password per il cisko */
111+
printf("Cisco login: ");
112+
fflush(stdout);
113+
fgets(login,25,stdin);
114+
printf("Cisco password: ");
115+
fflush(stdout);
116+
fgets(password,25,stdin);
117+
printf("\nConnecting.........");
118+
fflush(stdout);
119+
external_login(padip,login,password);
120+
if(logfile)
121+
freopen(logfile,"w",stdout);
122+
123+
for(i=0; i < strlen(buf); i++) {
124+
if(buf[i] == '>') break;
125+
prmpt[i]=buf[i];
126+
}
127+
prmpt[i]='\0';
128+
sleep(3);
129+
fprintf(fdw,"\n"); fflush(fdw);
130+
sleep(2);
131+
fn = 0;
132+
/* Qui parte la scansione vereppropria */
133+
fgets(buf,512,fdr); /* Questo e' il Trying .. bla bla bla */
134+
#ifdef DEBUG
135+
printf("%s",buf);
136+
#endif
137+
138+
for(i=nuastart;i<nuaend;i++) {
139+
if(!zbn) {
140+
if (dnic!=0)
141+
fprintf(fdw,"pad %d%d\n",dnic,i);
142+
else
143+
fprintf(fdw,"pad %d\n",i);
144+
}
145+
else
146+
fprintf(fdw,"pad 0%d%d\n",dnic,i);
147+
fflush(fdw);
148+
fgets(buf,512,fdr); /* Questo e' il Trying .. bla bla bla */
149+
#ifdef DEBUG
150+
printf("%s",buf);
151+
#endif
152+
fgets(buf,512,fdr); /* Questo e' il Trying .. bla bla bla */
153+
#ifdef DEBUG
154+
printf("%s",buf);
155+
#endif
156+
if((strstr(buf,"pen")!=NULL)) {
157+
if(!zbn) {
158+
if (dnic!=0)
159+
printf("NUA Found: %d%d\n",dnic,i);
160+
else
161+
printf("NUA Found: %d\n",i);
162+
}
163+
else
164+
printf("NUA Found: 0%d%d\n",dnic,i);
165+
166+
close(fdr);
167+
close(fdw);
168+
shutdown(s,2);
169+
external_login(padip,login,password);
170+
fn++;
171+
continue;
172+
}else {
173+
fgets(buf,512,fdr);
174+
#ifdef DEBUG
175+
printf("%s",buf);
176+
#endif
177+
fgets(buf,512,fdr);
178+
#ifdef DEBUG
179+
printf("%s",buf);
180+
#endif
181+
182+
if(!zbn) {
183+
if (dnic!=0)
184+
printf("NUA Dead: %d%d\n",dnic,i);
185+
else
186+
printf("NUA Dead: %d\n",i);
187+
}
188+
else
189+
printf("NUA Dead: 0%d%d\n",dnic,i);
190+
}
191+
fflush(stdout);
192+
}
193+
printf("Scan ended!\n");
194+
return fn;
195+
}
196+
197+
198+
199+
200+
201+
202+
203+
204+
void external_login(unsigned long padip,char login[25],char password[25])
205+
{
206+
207+
struct sockaddr_in sin;
208+
sin.sin_family=AF_INET; // Internet TCP/IP
209+
sin.sin_port = htons(23); // Porta 23
210+
sin.sin_addr.s_addr = padip; // Hostname->ip
211+
s = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP); // Kreo il soket
212+
if((connect(s,(struct sockaddr *)&sin,sizeof(sin)))==-1) { // mi connetto
213+
printf("Failed!\n"); // non s'e' connesso
214+
printf("Aborting.......\n");
215+
exit(203);
216+
}
217+
fdr=fdopen(s,"r"); // assegno ai file la scrittura e la lettura sul socket
218+
fdw=fdopen(s,"w");
219+
while(1) {
220+
fgets(buf,512,fdr); // Akkiappo dal socket
221+
#ifdef DEBUG
222+
printf("%s",buf);
223+
#endif
224+
if((strstr(buf,"Verification"))!=NULL) // Se trova la stringa verification allora esce
225+
break; // dal ciclo altrimenti ripija dal socket
226+
}
227+
228+
fprintf(fdw,"\n%s%s\n\n",login,password); fflush(fdw);
229+
fgets(buf,512,fdr);
230+
#ifdef DEBUG
231+
printf("%s",buf);
232+
#endif
233+
fgets(buf,512,fdr);
234+
#ifdef DEBUG
235+
printf("%s",buf);
236+
#endif
237+
fgets(buf,512,fdr);
238+
#ifdef DEBUG
239+
printf("%s",buf);
240+
#endif
241+
fgets(buf,512,fdr);
242+
#ifdef DEBUG
243+
printf("%s",buf);
244+
#endif
245+
fgets(buf,512,fdr);
246+
#ifdef DEBUG
247+
printf("%s",buf);
248+
#endif
249+
fgets(buf,512,fdr);
250+
#ifdef DEBUG
251+
printf("%s",buf);
252+
#endif
253+
if((strstr(buf,">"))==NULL) {
254+
printf("Login failed!\n");
255+
exit(205);
256+
}
257+
printf("Logged in\n");
258+
fgets(buf,512,fdr);
259+
#ifdef DEBUG
260+
printf("%s",buf);
261+
#endif
262+
263+
}

0 commit comments

Comments
 (0)