Lines 1-6
Link Here
|
1 |
--- netsed.c.orig Tue Jan 9 11:30:40 2001 |
1 |
--- netsed.c.orig Fri Jan 5 18:58:22 2001 |
2 |
+++ netsed.c Tue Jan 9 11:43:41 2001 |
2 |
+++ netsed.c Sun Aug 11 14:32:29 2002 |
3 |
@@ -134,8 +134,10 @@ |
3 |
@@ -2,6 +2,7 @@ |
|
|
4 |
#include <unistd.h> |
5 |
#include <sys/types.h> |
6 |
#include <sys/socket.h> |
7 |
+#include <sys/wait.h> |
8 |
#include <netinet/in.h> |
9 |
#include <arpa/inet.h> |
10 |
#include <fcntl.h> |
11 |
@@ -45,11 +46,11 @@ |
12 |
ERR("This will replace all occurences of pat1 with pat2 in matching packets.\n"); |
13 |
ERR("Additional parameter (count) can be used to expire rule after 'count'\n"); |
14 |
ERR("succesful substitutions. Eight-bit characters, including NULL and '/', can\n"); |
15 |
- ERR("be passed using HTTP-alike hex escape sequences (eg. %%0a%%0d). Single '%%'\n"); |
16 |
- ERR("can be reached by using '%%%%'. Examples:\n\n"); |
17 |
- ERR(" 's/anrew/mike/1' - replace 'andrew' with 'mike' (once)\n"); |
18 |
- ERR(" 's/anrew/mike' - replace all occurences of 'andrew' with 'mike'\n"); |
19 |
- ERR(" 's/anrew/mike%%00' - replace 'andrew' with 'mike\\x00' (to keep orig. size)\n"); |
20 |
+ ERR("be passed using HTTP-alike hex escape sequences (eg. CRLF -> %%0a%%0d).\n"); |
21 |
+ ERR("Single '%%' can be reached by using '%%%%'. Examples:\n\n"); |
22 |
+ ERR(" 's/andrew/mike/1' - replace 'andrew' with 'mike' (once)\n"); |
23 |
+ ERR(" 's/andrew/mike' - replace all occurences of 'andrew' with 'mike'\n"); |
24 |
+ ERR(" 's/andrew/mike%%00' - replace 'andrew' with 'mike\\x00' (to keep orig. size)\n"); |
25 |
ERR(" 's/%%%%/%%2f/20' - replace '%%' with '/' in first 20 packets\n\n"); |
26 |
ERR("Rules are not working on cross-packet boundaries and are evaluated from\n"); |
27 |
ERR("first to last not expired rule.\n"); |
28 |
@@ -134,8 +135,10 @@ |
4 |
|
29 |
|
5 |
|
30 |
|
6 |
void bind_and_listen(int tcp,int port) { |
31 |
void bind_and_listen(int tcp,int port) { |
Lines 11-17
Link Here
|
11 |
fcntl(lsock,F_SETFL,O_NONBLOCK); |
36 |
fcntl(lsock,F_SETFL,O_NONBLOCK); |
12 |
laddr.sin_family = PF_INET; |
37 |
laddr.sin_family = PF_INET; |
13 |
laddr.sin_port = htons (port); |
38 |
laddr.sin_port = htons (port); |
14 |
@@ -186,7 +188,6 @@ |
39 |
@@ -186,7 +189,6 @@ |
15 |
rd=read(s1,buf,sizeof(buf)); |
40 |
rd=read(s1,buf,sizeof(buf)); |
16 |
if (rd<0 && errno!=EAGAIN) return 0; // s1 not connected |
41 |
if (rd<0 && errno!=EAGAIN) return 0; // s1 not connected |
17 |
if (rd>0) { |
42 |
if (rd>0) { |
Lines 19-25
Link Here
|
19 |
printf("[+] Caught server -> client packet.\n"); |
44 |
printf("[+] Caught server -> client packet.\n"); |
20 |
rd=sed_the_buffer(rd); |
45 |
rd=sed_the_buffer(rd); |
21 |
if (write(s2,b2,rd)<=0) return 0; // not able to send |
46 |
if (write(s2,b2,rd)<=0) return 0; // not able to send |
22 |
@@ -195,7 +196,6 @@ |
47 |
@@ -195,7 +197,6 @@ |
23 |
rd=read(s2,buf,sizeof(buf)); |
48 |
rd=read(s2,buf,sizeof(buf)); |
24 |
if (rd<0 && errno!=EAGAIN) return 0; // s2 not connected |
49 |
if (rd<0 && errno!=EAGAIN) return 0; // s2 not connected |
25 |
if (rd>0) { |
50 |
if (rd>0) { |
Lines 27-29
Link Here
|
27 |
printf("[+] Caught client -> server packet.\n"); |
52 |
printf("[+] Caught client -> server packet.\n"); |
28 |
rd=sed_the_buffer(rd); |
53 |
rd=sed_the_buffer(rd); |
29 |
if (write(s1,b2,rd)<=0) return 0; // not able to send |
54 |
if (write(s1,b2,rd)<=0) return 0; // not able to send |
|
|
55 |
@@ -204,6 +205,14 @@ |
56 |
return 1; |
57 |
} |
58 |
|
59 |
+void sig_chld(int signo) |
60 |
+{ |
61 |
+ pid_t pid; |
62 |
+ int stat; |
63 |
+ while ( (pid = waitpid(-1, &stat, WNOHANG)) > 0) |
64 |
+ printf("child %d terminated\n", pid); |
65 |
+ return; |
66 |
+} |
67 |
|
68 |
int main(int argc,char* argv[]) { |
69 |
int i; |
70 |
@@ -242,7 +251,7 @@ |
71 |
if (fixedhost && fixedport) printf("[+] Using fixed forwarding to %s:%s.\n",argv[3],argv[4]); |
72 |
else printf("[+] Using dynamic (transparent proxy) forwarding.\n"); |
73 |
signal(SIGPIPE,SIG_IGN); |
74 |
- signal(SIGCHLD,SIG_IGN); |
75 |
+ signal(SIGCHLD,sig_chld); |
76 |
|
77 |
// Am I bad coder?;> |
78 |
|