/** * Formats raw HTTP_COOKIE data and stores it in map * * @param map the where to store the output * @param query the HTTP_COOKIE string */ void Compositor::formatCookieData(StrMap &map, std::string query) { if (query == "") return; std::string::size_type eqMarker = query.find("="); do { std::string::size_type pairMarker = query.find("; "); std::string key = query.substr(0, eqMarker); std::string val = query.substr(eqMarker + 1, pairMarker - eqMarker - 1); char* keyFinal = new char[key.size() + 1]; char* valFinal = new char[val.size() + 1]; urldecode2(keyFinal, key.c_str()); urldecode2(valFinal, val.c_str()); map.emplace(keyFinal, valFinal); delete [] keyFinal; delete [] valFinal; if (pairMarker == std::string::npos) pairMarker = query.size() - 1; query.replace(0, pairMarker + 2, ""); eqMarker = query.find("="); } while (eqMarker != std::string::npos); }
int main(int argc, char** argv) { if(argc<2) { fprintf(stderr, "Error: No config file was given to extract (it's likely named noip2.conf)\n"); exit(1); } FILE* f=fopen(argv[1],"r"); if(f==NULL) { fprintf(stderr, "Error: Unable to open config file\n"); exit(2); } size_t CONFIG_SIZE= sizeof(CONFIG); CONFIG config; if(fread(&config,1,CONFIG_SIZE,f)!=CONFIG_SIZE) { fprintf(stderr, "Error: Unable to read config file or corrupt config file\n"); exit(3); } size_t size = config.rlength; char* request = malloc(size + 1); // allow for bdecode expansion if (fread(request, 1, size,f) != size) { fprintf(stderr, "Error: Unable to read config file or corrupt config file \n"); exit(4); } request[size] = 0; char* decoded=base64_decode(request); free(request); printf("DEBUG: Decoded request: %s\n",decoded); char* username=decoded+strlen(USER_STR); char* password=strstr(username,PASS_STR); if(password==NULL) { fprintf(stderr, "Error: Malformed configuration file\n"); exit(5); } *password='******'; password+=strlen(PASS_STR); char* terminator=strchr(password,'&'); if(terminator==NULL) { fprintf(stderr, "Error: Malformed configuration file\n"); exit(6); } *terminator='\0'; //Now we url decode the username and password (in place is safe) urldecode2(username,username); urldecode2(password,password); printf("Successfully extracted acount information\nUsername: %s\nPassword: %s\n",username,password); free(decoded); }
int main() { char out[256]; char *in = "%7B%22message%22%3A%7B%22path%22%3A%22task%2Fssi%2Flive%22%2C%22date%22%3A%2220120725%22%2C%22endTime%22%3A%221350529600%22%2C%22taskid%22%3A998724866%2C%22beginTime%22%3A%221350527200%22%2C%22snapshotInterval%22%3A%22-1%22%2C%22ssgaddr%22%3A%22172.16.7.137%22%2C%22ssgport%22%3A554%7D%2C%22eventType%22%3A%7B%22eventCode%22%3A3%2C%22subEvent%22%3A0%7D%7D"; urldecode2(out, in); printf(" out data:%s\n", out); return 0; }
int processPostData(char *postData) { char *token; char buf[1024]; char decodedToken[100]; char action[80]; char section[80]; char field[80]; char value[80]; int smartDnsUpdatePerformed; char smartDnsProviderPrimary[1024]; char smartDnsProviderSecondary[1024]; int n; sscanf(postData, "action=%[0-9a-zA-Z]", &action); if(compStr(action, "update", sizearray(action))) { token = strtok (postData,"&"); while (token != NULL) { //check if contains / so we know it's a var to update urldecode2(decodedToken, token); if(strstr(decodedToken, "/") != NULL) { sscanf(decodedToken, "%[0-9a-zA-Z]/%[0-9a-zA-Z]=%[0-9a-zA-Z.:/_%-]", section, field, value); //check if DNS update and allowed to perform if(compStr(section, "DNS", sizearray(section)) && !compStr(field, "useDHCP", sizearray(field)) && (smartDnsUpdatePerformed == 1)) { //do nothing } else { n = write_config_var(section, field, value); } //Check if an update for smartDNS selected which is not set to other if(compStr(section, "SmartDNS", sizearray(section)) && compStr(field, "selected", sizearray(section)) && !compStr(value, "other", sizearray(section))) { strcpy(buf, "SmartDNS-"); strcat(buf, value); //get DNS details for SmartDNS provider read_config_var(buf, "primary", smartDnsProviderPrimary); read_config_var(buf, "secondary", smartDnsProviderSecondary); //set DNS details to selected SmartDNS Provider n = write_config_var("DNS", "primary", smartDnsProviderPrimary); n = write_config_var("DNS", "secondary", smartDnsProviderSecondary); //set that DNS update has been performed so any unwanted commits don't occur after smartDnsUpdatePerformed=1; } } token = strtok (NULL, "&"); } } }
String decodeB64(String text) { char buff[100]; urldecode2(buff, text.c_str()); return String(buff); }
//main function for web services int main(void) { long n; char strPage[1023]; char strFooters[1023]; char strHeaders[1023]; char strPopup[1023]; char str[1024]; char command[1024] = "echo Welcome to EurekaRom"; char decodedCommand[1024]; char *data; char *token; char *headers; char *page = NULL; const char *key, *value; char *postBuffer = NULL; int postRead; unsigned int postLen; char postData[4096]; char * queryString; char query_action[1024]; char query_section[1024]; char query_field[1024]; char query_value[1024]; data = malloc(QS_LEN); token = malloc(QS_LEN); key = malloc(QS_LEN); value = malloc(QS_LEN); //Operations if POST detected if(compStr(getenv("REQUEST_METHOD"), "POST", sizearray(getenv("REQUEST_METHOD")))) { if (getenv("QUERY_STRING")) { token = strtok (getenv("QUERY_STRING"),"&"); while (token != NULL) { sscanf(token, "%[^=]=%65536s", key, value); if ( compStr(key, "page", sizearray(key) )) { strcpy(strPage, value); } token = strtok (NULL, "&"); } } postRead = getline(&postBuffer, &postLen, stdin); if (-1 != postRead) { strcpy(postData, postBuffer); } if (compStr(strPage, "debug", sizearray(strPage) )) { sscanf(postData, "page=debug&command=%[^,]", command); urldecode2(decodedCommand, command); web_module_headers(strPage); web_module_debug(decodedCommand); web_module_footer(); } if (compStr(strPage, "settings", sizearray(strPage) )) { processPostData(postData); web_module_headers(strPage); web_module_settings(); web_module_footer(); } free(postBuffer); } else { if (!getenv("QUERY_STRING")) { //no query string web_module_headers("home"); web_module_home(); } if (getenv("QUERY_STRING")) { //parse Query_STRING for page //query string present token = strtok (getenv("QUERY_STRING"),"&"); while (token != NULL) { sscanf(token, "%[^=]=%65536s", key, value); if ( compStr(key, "page", sizearray(key) )) { strcpy(strPage, value); } if ( compStr(key, "headers", sizearray(key) )) { strcpy(strHeaders, value); } if ( compStr(key, "footers", sizearray(key) )) { strcpy(strFooters, value); } if ( compStr(key, "popup", sizearray(key) )) { strcpy(strPopup, value); } token = strtok (NULL, "&"); } // Call this before headers if ( compStr(strPage, "dumpstate", sizearray(strPage) )) { dumpstate(); exit(0); } //check for which page to load if ( compStr(strHeaders, "0", sizearray(strHeaders) )) { } else { web_module_headers(strPage); } if ( compStr(strPopup, "1", sizearray(strHeaders) )) { web_module_popup_headers(strPage); } if ( compStr(strPage, "home", sizearray(strPage) )) { web_module_home(); } if ( compStr(strPage, "logcat", sizearray(strPage) )) { web_module_logcat(); } if ( compStr(strPage, "forceeurekaupdate", sizearray(strPage) )) { forceeurekaupdate(); } if ( compStr(strPage, "debug", sizearray(strPage) )) { web_module_debug(command); } if ( compStr(strPage, "settings", sizearray(strPage) )) { web_module_settings(); } if ( compStr(strPage, "status", sizearray(strPage) )) { web_module_status(); } if ( compStr(strPage, "companion", sizearray(strPage) )) { web_module_companion(); } if ( compStr(strPage, "aboutus", sizearray(strPage) )) { web_module_aboutus(); } if ( compStr(strPage, "Reboot", sizearray(strPage) )) { reboot(); } if ( compStr(strPage, "sysupdate", sizearray(strPage) )) { sysupdate(); } if ( compStr(strPage, "factorydatareset", sizearray(strPage) )) { factorydatareset(); } if ( compStr(strFooters, "0", sizearray(strFooters) )) { } else { web_module_footer(); } } } }