source: titan/plugins/tithek/filenuke.h @ 24314

Last change on this file since 24314 was 24314, checked in by obi, 10 years ago

fix

File size: 9.2 KB
Line 
1#ifndef FILENUKE_H
2#define FILENUKE_H
3
4char* filenuke(char* host, char* file, char* hosterurl)
5{
6        debug(99, "in host: %s file: %s", host, file);
7        int debuglevel = getconfigint("debuglevel", NULL);
8        char* tmphost = NULL, *error = NULL, *tmpfile = NULL, *tmpstr = NULL, *send = NULL, *id = NULL, *fname = NULL, *op = NULL, *hash = NULL, *hashlen = NULL, *ip = NULL;
9        char* b36code = NULL, *base = NULL, *search = NULL, *post = NULL, *streamlink = NULL, *tmpstr2 = NULL, *tmpstr3 = NULL, *charlist = NULL;
10//      char* cmd = NULL;
11       
12        if(host == NULL || file == NULL) return NULL;
13
14        unlink("/tmp/filenuke1_get");
15        unlink("/tmp/filenuke2_post");
16        unlink("/tmp/filenuke3_tmpstr1");
17        unlink("/tmp/filenuke4_post2");
18        unlink("/tmp/filenuke5_tmpstr2");
19        unlink("/tmp/filenuke6_b36code2");
20        unlink("/tmp/filenuke7_tmpstr_last");
21        unlink("/tmp/filenuke8_streamlink");
22
23        tmphost = ostrcat("www.", host, 0, 0);
24        tmpfile = ostrcat("/", file, 0, 0);
25        debug(99, "tmphost: %s", tmphost);
26        ip = get_ip(tmphost);
27        debug(99, "ip: %s", ip);
28        debug(99, "test host only: %s", get_ip(host));
29        debug(99, "tmpfile: %s", tmpfile);
30
31        send = ostrcat(send, "GET ", 1, 0);
32        send = ostrcat(send, tmpfile, 1, 0);
33        send = ostrcat(send, " HTTP/1.1\r\nAccept-Encoding: identity\r\n", 1, 0);
34        send = ostrcat(send, "Accept-Language: de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4\r\n", 1, 0);
35        send = ostrcat(send, "Host: ", 1, 0);
36        send = ostrcat(send, tmphost, 1, 0);
37        send = ostrcat(send, "\r\nUser-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de-DE; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3\r\n", 1, 0);
38        send = ostrcat(send, "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\n", 1, 0);
39        send = ostrcat(send, "Connection: close\r\nCookie: xxx2=ok;\r\n\r\n", 1, 0);
40        debug(99, "send: %s", send);
41
42        tmpstr = gethttpreal(tmphost, tmpfile, 80, NULL, NULL, NULL, 0, send, NULL, 5000, 1);
43        free(send), send = NULL;
44        debug(99, "tmpstr: %s", tmpstr);
45        titheklog(debuglevel, "/tmp/filenuke1_get", NULL, tmpstr);
46
47//      sleep(2);
48
49        if(ostrstr(tmpstr, "<title>The page is temporarily unavailable</title>") != NULL)
50        {
51                error = string_resub("<td align=\"center\" valign=\"middle\">", "</td>", tmpstr, 0);
52                string_deltags(error);
53                stringreplacechar(error, '|', '\0');
54                error = strstrip(error);
55                if(error == NULL || strlen(error) == 0)
56                        error = ostrcat(_("The page is temporarily unavailable"), error, 0, 1);
57                textbox(_("Message"), error, _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 1200, 400, 0, 0);
58                goto end;
59        }
60
61        if(ostrstr(tmpstr, "<title>Direct IP access not allowed") != NULL)
62        {
63                error = string_resub("<title>", "</title>", tmpstr, 0);
64                string_deltags(error);
65                stringreplacechar(error, '|', '\0');
66                error = strstrip(error);
67                if(error == NULL || strlen(error) == 0)
68                        error = ostrcat(_("The page is temporarily unavailable"), error, 0, 1);
69                textbox(_("Message"), error, _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 1200, 400, 0, 0);
70                goto end;
71        }
72
73        //get hash from tmpstr
74        char* pos1 = ostrstr(tmpstr, "<input type=\"hidden\" name=\"fname\" value=");
75        fname = getxmlentry(pos1, "value=");
76        debug(99, "fname: %s", fname);
77        if(fname == NULL) goto end;
78
79        char* pos2 = ostrstr(tmpstr, "<input type=\"hidden\" name=\"id\" value=");
80        id = getxmlentry(pos2, "value=");
81        debug(99, "id: %s", id);
82        if(id == NULL) goto end;
83
84        char* pos3 = ostrstr(tmpstr, "<input type=\"hidden\" name=\"op\" value=");
85        op = getxmlentry(pos3, "value=");
86        free(tmpstr); tmpstr = NULL;
87        debug(99, "op: %s", op);
88        if(op == NULL) goto end;
89
90        hash = ostrcat(hash, "id=", 1, 0);     
91        hash = ostrcat(hash, id, 1, 0);
92        hash = ostrcat(hash, "&referer=&fname=", 1, 0);
93        hash = ostrcat(hash, fname, 1, 0);
94        hash = ostrcat(hash, "&method_free=Free&usr_login=&op=", 1, 0);
95        hash = ostrcat(hash, op, 1, 0);
96        debug(99, "hash: %s", hash);
97
98        hashlen = oitoa(strlen(hash));
99       
100        //create send string
101        send = ostrcat(send, "POST /", 1, 0);
102        send = ostrcat(send, id, 1, 0);
103        send = ostrcat(send, " HTTP/1.0\r\nContent-Length: ", 1, 0);
104        send = ostrcat(send, hashlen, 1, 0);
105        send = ostrcat(send, "\r\nAccept-Encoding: gzip\r\nConnection: close\r\nUser-Agent: Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.99 Safari/535.1\r\nHost: ", 1, 0);
106        send = ostrcat(send, tmphost, 1, 0);
107        send = ostrcat(send, "\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\n", 1, 0);
108        send = ostrcat(send, hash, 1, 0);
109        debug(99, "send: %s", send);
110
111//      sleep(5);
112       
113        post = gethttpreal(tmphost, tmpfile, 80, NULL, NULL, NULL, 0, send, NULL, 5000, 0);
114        free(send), send = NULL;
115        debug(99, "post: %s", post);
116        titheklog(debuglevel, "/tmp/filenuke2_post", NULL, tmpstr);
117
118        free(tmpstr),tmpstr = NULL;
119        tmpstr = string_resub(";return p}('", ");'", post, 0);
120        debug(99, "tmpstr: %s", tmpstr);
121        titheklog(debuglevel, "/tmp/filenuke3_tmpstr1", NULL, tmpstr);
122       
123        post = string_replace_all(tmpstr, "", post, 1);
124        post = string_replace_all(";return p}(');'", "", post, 1);
125        debug(99, "post: %s", post);
126        titheklog(debuglevel, "/tmp/filenuke4_post2", NULL, post);
127
128        free(tmpstr),tmpstr = NULL;
129        free(b36code),b36code = NULL;
130        tmpstr = string_resub(";return p}('", ");'", post, 0);
131        debug(99, "tmpstr: %s", tmpstr);
132        titheklog(debuglevel, "/tmp/filenuke5_tmpstr2", NULL, tmpstr);
133
134        b36code = oregex(".*;',[0-9]{2,2},[0-9]{2,2},'(.*)'.split.*", post);
135       
136        b36code = string_replace_all("||", "| |", b36code, 1);
137        debug(99, "b36code: %s", b36code);
138        titheklog(debuglevel, "/tmp/filenuke6_b36code2", NULL, b36code);
139       
140        struct splitstr* ret1 = NULL;
141        int count = 0;
142        int i = 0;
143        ret1 = strsplit(b36code, "|", &count);
144
145        charlist = ostrcat(charlist, "\"", 1, 0);
146        charlist = ostrcat(charlist, "|", 1, 0);
147        charlist = ostrcat(charlist, "'", 1, 0);
148        charlist = ostrcat(charlist, "|", 1, 0);
149        charlist = ostrcat(charlist, ".", 1, 0);
150        charlist = ostrcat(charlist, "|", 1, 0);
151        charlist = ostrcat(charlist, ";", 1, 0);
152        charlist = ostrcat(charlist, "|", 1, 0);
153        charlist = ostrcat(charlist, ":", 1, 0);
154        charlist = ostrcat(charlist, "|", 1, 0);
155        charlist = ostrcat(charlist, "=", 1, 0);
156        charlist = ostrcat(charlist, "|", 1, 0);
157        charlist = ostrcat(charlist, ",", 1, 0);
158        charlist = ostrcat(charlist, "|", 1, 0);
159        charlist = ostrcat(charlist, " ", 1, 0);
160        charlist = ostrcat(charlist, "|", 1, 0);
161        charlist = ostrcat(charlist, "\\", 1, 0);
162        charlist = ostrcat(charlist, "|", 1, 0);
163        charlist = ostrcat(charlist, "/", 1, 0);
164        charlist = ostrcat(charlist, "|", 1, 0);
165        charlist = ostrcat(charlist, "(", 1, 0);
166        charlist = ostrcat(charlist, "|", 1, 0);
167        charlist = ostrcat(charlist, ")", 1, 0);
168
169        for(i = 0; i < count; i++)
170        {
171                if(ostrstr((&ret1[i])->part, " ") != NULL)
172                {
173                        printf("continue\n");
174                        continue;
175                }
176                char* x = oltostr(i, 36);
177
178                struct splitstr* ret2 = NULL;
179                int count2 = 0;
180                int i2 = 0;
181                tmpstr2 = ostrcat(charlist, NULL, 0, 0);
182                ret2 = strsplit(tmpstr2, "|", &count2);
183                for(i2 = 0; i2 < count2; i2++)
184                {
185                        struct splitstr* ret3 = NULL;
186                        int count3 = 0;
187                        int i3 = 0;
188                        tmpstr3 = ostrcat(charlist, NULL, 0, 0);
189                        ret3 = strsplit(tmpstr3, "|", &count3);
190                        for(i3 = 0; i3 < count3; i3++)
191                        {
192                                debug(99, "-----------------------------------------------");
193                                debug(99, "replace %s%s%s <> %s%s%s",(&ret2[i2])->part, x, (&ret3[i3])->part, (&ret2[i2])->part, (&ret1[i])->part, (&ret3[i3])->part);
194
195                                base = ostrcat(base, (&ret2[i2])->part, 1, 0);
196                                base = ostrcat(base, x, 1, 0);
197                                base = ostrcat(base, (&ret3[i3])->part, 1, 0);         
198                                search = ostrcat(search, (&ret2[i2])->part, 1, 0);
199                                search = ostrcat(search, (&ret1[i])->part, 1, 0);
200                                search = ostrcat(search, (&ret3[i3])->part, 1, 0);
201                                tmpstr = string_replace_all(base, search, tmpstr, 1);
202                                free(base), base = NULL;
203                                free(search), search = NULL;
204                        }
205                        free(ret3), ret3 = NULL;
206                        free(tmpstr3), tmpstr3 = NULL;
207                }
208                free(ret2), ret2 = NULL;
209                free(tmpstr2), tmpstr2 = NULL;
210                free(x);
211        }
212        free(ret1), ret1 = NULL;
213        free(b36code), b36code = NULL;
214        free(post), post = NULL;
215        free(charlist), charlist = NULL;
216
217        titheklog(debuglevel, "/tmp/filenuke7_tmpstr_last", NULL, tmpstr);
218
219        streamlink = oregex(".*file.*(http:.*video.flv).*image.*", tmpstr);
220        if(streamlink == NULL)
221                streamlink = oregex(".*file.*(http:.*video.mp4).*image.*", tmpstr);                             
222
223        if(streamlink == NULL)
224                streamlink = oregex(".*file.*(http:.*video.mkv).*image.*", tmpstr);
225
226        if(streamlink == NULL)
227                streamlink = oregex(".*file.*(http:.*video.avi).*image.*", tmpstr);
228
229        if(streamlink == NULL)
230                streamlink = oregex(".*src=.*(http:.*video.mp4).*\".*", tmpstr);
231
232        if(streamlink == NULL)
233                streamlink = oregex(".*src=.*(http:.*video.mkv).*\".*", tmpstr);
234
235        if(streamlink == NULL)
236                streamlink = oregex(".*src=.*(http:.*video.avi).*\".*", tmpstr);
237               
238        if(streamlink == NULL)
239                streamlink = oregex(".*value=.*(http:.*video.mp4).*\".*", tmpstr);                             
240
241        if(streamlink == NULL)
242                streamlink = oregex(".*value=.*(http:.*video.mkv).*\".*", tmpstr);
243
244        if(streamlink == NULL)
245                streamlink = oregex(".*value=.*(http:.*video.avi).*\".*", tmpstr);                     
246
247        titheklog(debuglevel, "/tmp/filenuke8_streamlink", NULL, streamlink);
248
249        free(tmpstr); tmpstr = NULL;
250
251end:
252
253        free(error); error = NULL;
254        free(tmphost); tmphost = NULL;
255        free(tmpfile); tmpfile = NULL;
256        free(tmpstr); tmpstr = NULL;
257        free(send); send = NULL;
258        free(hash), hash = NULL;
259        free(hashlen), hashlen = NULL;
260        free(op), op = NULL;
261        free(id), id = NULL;
262        free(fname), fname = NULL;
263        free(ip); ip = NULL;
264
265        return streamlink;
266}
267
268#endif
Note: See TracBrowser for help on using the repository browser.