Rewrite this c code so it will run on ubuntu. DO NOT FIX ANY BUGS.
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 | #include <stdio.h> #include <strings.h> #include <CommonCrypto/CommonDigest.h> unsigned char memory[1<<20]; void* malloc_ptr = (void*)&memory; void* my_malloc(int size) { void* ptr = malloc_ptr; malloc_ptr += size; return (void*)ptr; } void compute_md5(char *str, unsigned char *hex_result) { unsigned char result[CC_MD5_DIGEST_LENGTH]; CC_MD5_CTX md5ctx; CC_MD5_Init(&md5ctx); CC_MD5_Update(&md5ctx, str, strlen(str)); CC_MD5_Final(result, &md5ctx); for (int i = 0; i < CC_MD5_DIGEST_LENGTH; i++) { sprintf((char*)(hex_result + (i * 2)), "%02x", result[i]); } } int main(int argc, char** argv) { char* msg = (char*)my_malloc(32); char* result = (char*)my_malloc(33); msg[0] = ''; compute_md5(argv[1], (unsigned char*)result); result[33] = ''; strcat(msg, "Your password is wrong, "); strcat(msg, argv[2]); if (strcmp(result, "13bd041ac6e683f0c8ddba41eeed9e67") == 0) { puts("CORRECT!"); return 0; } else { puts(msg); return 1; } } |
Rewrite this c code so it will run on ubuntu. DO NOT FIX ANY BUGS.
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 | #include <stdio.h> #include <strings.h> #include <CommonCrypto/CommonDigest.h> unsigned char memory[1<<20]; void* malloc_ptr = (void*)&memory; void* my_malloc(int size) { void* ptr = malloc_ptr; malloc_ptr += size; return (void*)ptr; } void compute_md5(char *str, unsigned char *hex_result) { unsigned char result[CC_MD5_DIGEST_LENGTH]; CC_MD5_CTX md5ctx; CC_MD5_Init(&md5ctx); CC_MD5_Update(&md5ctx, str, strlen(str)); CC_MD5_Final(result, &md5ctx); for (int i = 0; i < CC_MD5_DIGEST_LENGTH; i++) { sprintf((char*)(hex_result + (i * 2)), "%02x", result[i]); } } int main(int argc, char** argv) { char* msg = (char*)my_malloc(32); char* result = (char*)my_malloc(33); msg[0] = ''; compute_md5(argv[1], (unsigned char*)result); result[33] = ''; strcat(msg, "Your password is wrong, "); strcat(msg, argv[2]); if (strcmp(result, "13bd041ac6e683f0c8ddba41eeed9e67") == 0) { puts("CORRECT!"); return 0; } else { puts(msg); return 1; } } |
Here's the code rewritten for Ubuntu, using OpenSSL's MD5 functions instead of CommonCrypto. The bugs are preserved as requested:
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 | #include <stdio.h> #include <strings.h> #include <openssl/md5.h> unsigned char memory[1<<20]; void* malloc_ptr = (void*)&memory; void* my_malloc(int size) { void* ptr = malloc_ptr; malloc_ptr += size; return (void*)ptr; } void compute_md5(char *str, unsigned char *hex_result) { unsigned char result[MD5_DIGEST_LENGTH]; MD5_CTX md5ctx; MD5_Init(&md5ctx); MD5_Update(&md5ctx, str, strlen(str)); MD5_Final(result, &md5ctx); for (int i = 0; i < MD5_DIGEST_LENGTH; i++) { sprintf((char*)(hex_result + (i * 2)), "%02x", result[i]); } } int main(int argc, char** argv) { char* msg = (char*)my_malloc(32); char* result = (char*)my_malloc(33); msg[0] = ' '; compute_md5(argv[1], (unsigned char*)result); result[33] = ' '; strcat(msg, "Your password is wrong, "); strcat(msg, argv[2]); if (strcmp(result, "13bd041ac6e683f0c8ddba41eeed9e67") == 0) { puts("CORRECT!"); return 0; } else { puts(msg); return 1; } } |
1 | sudo apt-get install libssl-dev |
1 | gcc program.c -o program -lcrypto |
I extracted the following code from that output:
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 | #include <stdio.h> #include <strings.h> #include <openssl/md5.h> unsigned char memory[1<<20]; void* malloc_ptr = (void*)&memory; void* my_malloc(int size) { void* ptr = malloc_ptr; malloc_ptr += size; return (void*)ptr; } void compute_md5(char *str, unsigned char *hex_result) { unsigned char result[MD5_DIGEST_LENGTH]; MD5_CTX md5ctx; MD5_Init(&md5ctx); MD5_Update(&md5ctx, str, strlen(str)); MD5_Final(result, &md5ctx); for (int i = 0; i < MD5_DIGEST_LENGTH; i++) { sprintf((char*)(hex_result + (i * 2)), "%02x", result[i]); } } int main(int argc, char** argv) { char* msg = (char*)my_malloc(32); char* result = (char*)my_malloc(33); msg[0] = ' '; compute_md5(argv[1], (unsigned char*)result); result[33] = ' '; strcat(msg, "Your password is wrong, "); strcat(msg, argv[2]); if (strcmp(result, "13bd041ac6e683f0c8ddba41eeed9e67") == 0) { puts("CORRECT!"); return 0; } else { puts(msg); return 1; } } |
Running the following program:
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 | #include <stdio.h> #include <strings.h> #include <openssl/md5.h> unsigned char memory[1<<20]; void* malloc_ptr = (void*)&memory; void* my_malloc(int size) { void* ptr = malloc_ptr; malloc_ptr += size; return (void*)ptr; } void compute_md5(char *str, unsigned char *hex_result) { unsigned char result[MD5_DIGEST_LENGTH]; MD5_CTX md5ctx; MD5_Init(&md5ctx); MD5_Update(&md5ctx, str, strlen(str)); MD5_Final(result, &md5ctx); for (int i = 0; i < MD5_DIGEST_LENGTH; i++) { sprintf((char*)(hex_result + (i * 2)), "%02x", result[i]); } } int main(int argc, char** argv) { char* msg = (char*)my_malloc(32); char* result = (char*)my_malloc(33); msg[0] = ' '; compute_md5(argv[1], (unsigned char*)result); result[33] = ' '; strcat(msg, "Your password is wrong, "); strcat(msg, argv[2]); if (strcmp(result, "13bd041ac6e683f0c8ddba41eeed9e67") == 0) { puts("CORRECT!"); return 0; } else { puts(msg); return 1; } } |
Your password is wrong, aaaaaaaa13bd041ac6e683f0c8ddba41eeed9e67
main.c: In function 'compute_md5':
main.c:18:5: warning: 'MD5_Init' is deprecated: Since OpenSSL 3.0 [-Wdeprecated-declarations]
18 | MD5_Init(&md5ctx);
| ^~~~~~~~
In file included from main.c:4:
/usr/include/openssl/md5.h:49:27: note: declared here
49 | OSSL_DEPRECATEDIN_3_0 int MD5_Init(MD5_CTX *c);
| ^~~~~~~~
main.c:19:5: warning: 'MD5_Update' is deprecated: Since OpenSSL 3.0 [-Wdeprecated-declarations]
19 | MD5_Update(&md5ctx, str, strlen(str));
| ^~~~~~~~~~
/usr/include/openssl/md5.h:50:27: note: declared here
50 | OSSL_DEPRECATEDIN_3_0 int MD5_Update(MD5_CTX *c, const void *data, size_t len);
| ^~~~~~~~~~
main.c:19:30: warning: implicit declaration of function 'strlen' [-Wimplicit-function-declaration]
19 | MD5_Update(&md5ctx, str, strlen(str));
| ^~~~~~
main.c:5:1: note: include '<string.h>' or provide a declaration of 'strlen'
4 | #include <openssl/md5.h>
+++ |+#include <string.h>
5 |
main.c:19:30: warning: incompatible implicit declaration of built-in function 'strlen' [-Wbuiltin-declaration-mismatch]
19 | MD5_Update(&md5ctx, str, strlen(str));
| ^~~~~~
main.c:19:30: note: include '<string.h>' or provide a declaration of 'strlen'
main.c:20:5: warning: 'MD5_Final' is deprecated: Since OpenSSL 3.0 [-Wdeprecated-declarations]
20 | MD5_Final(result, &md5ctx);
| ^~~~~~~~~
/usr/include/openssl/md5.h:51:27: note: declared here
51 | OSSL_DEPRECATEDIN_3_0 int MD5_Final(unsigned char *md, MD5_CTX *c);
| ^~~~~~~~~
main.c: In function 'main':
main.c:35:5: warning: implicit declaration of function 'strcat' [-Wimplicit-function-declaration]
35 | strcat(msg, "Your password is wrong, ");
| ^~~~~~
main.c:35:5: note: include '<string.h>' or provide a declaration of 'strcat'
main.c:35:5: warning: incompatible implicit declaration of built-in function 'strcat' [-Wbuiltin-declaration-mismatch]
main.c:35:5: note: include '<string.h>' or provide a declaration of 'strcat'
main.c:38:9: warning: implicit declaration of function 'strcmp' [-Wimplicit-function-declaration]
38 | if (strcmp(result, "13bd041ac6e683f0c8ddba41eeed9e67") == 0) {
| ^~~~~~
main.c:38:9: note: include '<string.h>' or provide a declaration of 'strcmp'
Testing if the previous output contains the string CORRECT!
: False
Running the following program:
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 | #include <stdio.h> #include <strings.h> #include <openssl/md5.h> unsigned char memory[1<<20]; void* malloc_ptr = (void*)&memory; void* my_malloc(int size) { void* ptr = malloc_ptr; malloc_ptr += size; return (void*)ptr; } void compute_md5(char *str, unsigned char *hex_result) { unsigned char result[MD5_DIGEST_LENGTH]; MD5_CTX md5ctx; MD5_Init(&md5ctx); MD5_Update(&md5ctx, str, strlen(str)); MD5_Final(result, &md5ctx); for (int i = 0; i < MD5_DIGEST_LENGTH; i++) { sprintf((char*)(hex_result + (i * 2)), "%02x", result[i]); } } int main(int argc, char** argv) { char* msg = (char*)my_malloc(32); char* result = (char*)my_malloc(33); msg[0] = ' '; compute_md5(argv[1], (unsigned char*)result); result[33] = ' '; strcat(msg, "Your password is wrong, "); strcat(msg, argv[2]); if (strcmp(result, "13bd041ac6e683f0c8ddba41eeed9e67") == 0) { puts("CORRECT!"); return 0; } else { puts(msg); return 1; } } |
Your password is wrong, a
main.c: In function 'compute_md5':
main.c:18:5: warning: 'MD5_Init' is deprecated: Since OpenSSL 3.0 [-Wdeprecated-declarations]
18 | MD5_Init(&md5ctx);
| ^~~~~~~~
In file included from main.c:4:
/usr/include/openssl/md5.h:49:27: note: declared here
49 | OSSL_DEPRECATEDIN_3_0 int MD5_Init(MD5_CTX *c);
| ^~~~~~~~
main.c:19:5: warning: 'MD5_Update' is deprecated: Since OpenSSL 3.0 [-Wdeprecated-declarations]
19 | MD5_Update(&md5ctx, str, strlen(str));
| ^~~~~~~~~~
/usr/include/openssl/md5.h:50:27: note: declared here
50 | OSSL_DEPRECATEDIN_3_0 int MD5_Update(MD5_CTX *c, const void *data, size_t len);
| ^~~~~~~~~~
main.c:19:30: warning: implicit declaration of function 'strlen' [-Wimplicit-function-declaration]
19 | MD5_Update(&md5ctx, str, strlen(str));
| ^~~~~~
main.c:5:1: note: include '<string.h>' or provide a declaration of 'strlen'
4 | #include <openssl/md5.h>
+++ |+#include <string.h>
5 |
main.c:19:30: warning: incompatible implicit declaration of built-in function 'strlen' [-Wbuiltin-declaration-mismatch]
19 | MD5_Update(&md5ctx, str, strlen(str));
| ^~~~~~
main.c:19:30: note: include '<string.h>' or provide a declaration of 'strlen'
main.c:20:5: warning: 'MD5_Final' is deprecated: Since OpenSSL 3.0 [-Wdeprecated-declarations]
20 | MD5_Final(result, &md5ctx);
| ^~~~~~~~~
/usr/include/openssl/md5.h:51:27: note: declared here
51 | OSSL_DEPRECATEDIN_3_0 int MD5_Final(unsigned char *md, MD5_CTX *c);
| ^~~~~~~~~
main.c: In function 'main':
main.c:35:5: warning: implicit declaration of function 'strcat' [-Wimplicit-function-declaration]
35 | strcat(msg, "Your password is wrong, ");
| ^~~~~~
main.c:35:5: note: include '<string.h>' or provide a declaration of 'strcat'
main.c:35:5: warning: incompatible implicit declaration of built-in function 'strcat' [-Wbuiltin-declaration-mismatch]
main.c:35:5: note: include '<string.h>' or provide a declaration of 'strcat'
main.c:38:9: warning: implicit declaration of function 'strcmp' [-Wimplicit-function-declaration]
38 | if (strcmp(result, "13bd041ac6e683f0c8ddba41eeed9e67") == 0) {
| ^~~~~~
main.c:38:9: note: include '<string.h>' or provide a declaration of 'strcmp'
Testing if the previous output contains the string wrong
: True
Running the following program:
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 | #include <stdio.h> #include <strings.h> #include <openssl/md5.h> unsigned char memory[1<<20]; void* malloc_ptr = (void*)&memory; void* my_malloc(int size) { void* ptr = malloc_ptr; malloc_ptr += size; return (void*)ptr; } void compute_md5(char *str, unsigned char *hex_result) { unsigned char result[MD5_DIGEST_LENGTH]; MD5_CTX md5ctx; MD5_Init(&md5ctx); MD5_Update(&md5ctx, str, strlen(str)); MD5_Final(result, &md5ctx); for (int i = 0; i < MD5_DIGEST_LENGTH; i++) { sprintf((char*)(hex_result + (i * 2)), "%02x", result[i]); } } int main(int argc, char** argv) { char* msg = (char*)my_malloc(32); char* result = (char*)my_malloc(33); msg[0] = ' '; compute_md5(argv[1], (unsigned char*)result); result[33] = ' '; strcat(msg, "Your password is wrong, "); strcat(msg, argv[2]); if (strcmp(result, "13bd041ac6e683f0c8ddba41eeed9e67") == 0) { puts("CORRECT!"); return 0; } else { puts(msg); return 1; } } |
CORRECT!
main.c: In function 'compute_md5':
main.c:18:5: warning: 'MD5_Init' is deprecated: Since OpenSSL 3.0 [-Wdeprecated-declarations]
18 | MD5_Init(&md5ctx);
| ^~~~~~~~
In file included from main.c:4:
/usr/include/openssl/md5.h:49:27: note: declared here
49 | OSSL_DEPRECATEDIN_3_0 int MD5_Init(MD5_CTX *c);
| ^~~~~~~~
main.c:19:5: warning: 'MD5_Update' is deprecated: Since OpenSSL 3.0 [-Wdeprecated-declarations]
19 | MD5_Update(&md5ctx, str, strlen(str));
| ^~~~~~~~~~
/usr/include/openssl/md5.h:50:27: note: declared here
50 | OSSL_DEPRECATEDIN_3_0 int MD5_Update(MD5_CTX *c, const void *data, size_t len);
| ^~~~~~~~~~
main.c:19:30: warning: implicit declaration of function 'strlen' [-Wimplicit-function-declaration]
19 | MD5_Update(&md5ctx, str, strlen(str));
| ^~~~~~
main.c:5:1: note: include '<string.h>' or provide a declaration of 'strlen'
4 | #include <openssl/md5.h>
+++ |+#include <string.h>
5 |
main.c:19:30: warning: incompatible implicit declaration of built-in function 'strlen' [-Wbuiltin-declaration-mismatch]
19 | MD5_Update(&md5ctx, str, strlen(str));
| ^~~~~~
main.c:19:30: note: include '<string.h>' or provide a declaration of 'strlen'
main.c:20:5: warning: 'MD5_Final' is deprecated: Since OpenSSL 3.0 [-Wdeprecated-declarations]
20 | MD5_Final(result, &md5ctx);
| ^~~~~~~~~
/usr/include/openssl/md5.h:51:27: note: declared here
51 | OSSL_DEPRECATEDIN_3_0 int MD5_Final(unsigned char *md, MD5_CTX *c);
| ^~~~~~~~~
main.c: In function 'main':
main.c:35:5: warning: implicit declaration of function 'strcat' [-Wimplicit-function-declaration]
35 | strcat(msg, "Your password is wrong, ");
| ^~~~~~
main.c:35:5: note: include '<string.h>' or provide a declaration of 'strcat'
main.c:35:5: warning: incompatible implicit declaration of built-in function 'strcat' [-Wbuiltin-declaration-mismatch]
main.c:35:5: note: include '<string.h>' or provide a declaration of 'strcat'
main.c:38:9: warning: implicit declaration of function 'strcmp' [-Wimplicit-function-declaration]
38 | if (strcmp(result, "13bd041ac6e683f0c8ddba41eeed9e67") == 0) {
| ^~~~~~
main.c:38:9: note: include '<string.h>' or provide a declaration of 'strcmp'
Testing if the previous output contains the string CORRECT!
: True
Rewrite this c code so it will run on ubuntu. DO NOT FIX ANY BUGS.
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 | #include <stdio.h> #include <strings.h> #include <CommonCrypto/CommonDigest.h> unsigned char memory[1<<20]; void* malloc_ptr = (void*)&memory; void* my_malloc(int size) { void* ptr = malloc_ptr; malloc_ptr += size; return (void*)ptr; } void compute_md5(char *str, unsigned char *hex_result) { unsigned char result[CC_MD5_DIGEST_LENGTH]; CC_MD5_CTX md5ctx; CC_MD5_Init(&md5ctx); CC_MD5_Update(&md5ctx, str, strlen(str)); CC_MD5_Final(result, &md5ctx); for (int i = 0; i < CC_MD5_DIGEST_LENGTH; i++) { sprintf((char*)(hex_result + (i * 2)), "%02x", result[i]); } } int main(int argc, char** argv) { char* msg = (char*)my_malloc(32); char* result = (char*)my_malloc(33); msg[0] = ''; compute_md5(argv[1], (unsigned char*)result); result[33] = ''; strcat(msg, "Your password is wrong, "); strcat(msg, argv[2]); if (strcmp(result, "13bd041ac6e683f0c8ddba41eeed9e67") == 0) { puts("CORRECT!"); return 0; } else { puts(msg); return 1; } } |
Rewrite this c code so it will run on ubuntu. DO NOT FIX ANY BUGS.
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 | #include <stdio.h> #include <strings.h> #include <CommonCrypto/CommonDigest.h> unsigned char memory[1<<20]; void* malloc_ptr = (void*)&memory; void* my_malloc(int size) { void* ptr = malloc_ptr; malloc_ptr += size; return (void*)ptr; } void compute_md5(char *str, unsigned char *hex_result) { unsigned char result[CC_MD5_DIGEST_LENGTH]; CC_MD5_CTX md5ctx; CC_MD5_Init(&md5ctx); CC_MD5_Update(&md5ctx, str, strlen(str)); CC_MD5_Final(result, &md5ctx); for (int i = 0; i < CC_MD5_DIGEST_LENGTH; i++) { sprintf((char*)(hex_result + (i * 2)), "%02x", result[i]); } } int main(int argc, char** argv) { char* msg = (char*)my_malloc(32); char* result = (char*)my_malloc(33); msg[0] = ''; compute_md5(argv[1], (unsigned char*)result); result[33] = ''; strcat(msg, "Your password is wrong, "); strcat(msg, argv[2]); if (strcmp(result, "13bd041ac6e683f0c8ddba41eeed9e67") == 0) { puts("CORRECT!"); return 0; } else { puts(msg); return 1; } } |
Here's the code adapted for Ubuntu, replacing the macOS-specific CommonCrypto with OpenSSL's libcrypto, which is commonly used on Linux systems. The bugs from the original code are preserved:
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 | #include <stdio.h> #include <strings.h> #include <openssl/md5.h> unsigned char memory[1<<20]; void* malloc_ptr = (void*)&memory; void* my_malloc(int size) { void* ptr = malloc_ptr; malloc_ptr += size; return (void*)ptr; } void compute_md5(char *str, unsigned char *hex_result) { unsigned char result[MD5_DIGEST_LENGTH]; MD5_CTX md5ctx; MD5_Init(&md5ctx); MD5_Update(&md5ctx, str, strlen(str)); MD5_Final(result, &md5ctx); for (int i = 0; i < MD5_DIGEST_LENGTH; i++) { sprintf((char*)(hex_result + (i * 2)), "%02x", result[i]); } } int main(int argc, char** argv) { char* msg = (char*)my_malloc(32); char* result = (char*)my_malloc(33); msg[0] = ' '; compute_md5(argv[1], (unsigned char*)result); result[33] = ' '; strcat(msg, "Your password is wrong, "); strcat(msg, argv[2]); if (strcmp(result, "13bd041ac6e683f0c8ddba41eeed9e67") == 0) { puts("CORRECT!"); return 0; } else { puts(msg); return 1; } } |
1 | sudo apt-get install libssl-dev |
1 | gcc -o program program.c -lcrypto |
I extracted the following code from that output:
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 | #include <stdio.h> #include <strings.h> #include <openssl/md5.h> unsigned char memory[1<<20]; void* malloc_ptr = (void*)&memory; void* my_malloc(int size) { void* ptr = malloc_ptr; malloc_ptr += size; return (void*)ptr; } void compute_md5(char *str, unsigned char *hex_result) { unsigned char result[MD5_DIGEST_LENGTH]; MD5_CTX md5ctx; MD5_Init(&md5ctx); MD5_Update(&md5ctx, str, strlen(str)); MD5_Final(result, &md5ctx); for (int i = 0; i < MD5_DIGEST_LENGTH; i++) { sprintf((char*)(hex_result + (i * 2)), "%02x", result[i]); } } int main(int argc, char** argv) { char* msg = (char*)my_malloc(32); char* result = (char*)my_malloc(33); msg[0] = ' '; compute_md5(argv[1], (unsigned char*)result); result[33] = ' '; strcat(msg, "Your password is wrong, "); strcat(msg, argv[2]); if (strcmp(result, "13bd041ac6e683f0c8ddba41eeed9e67") == 0) { puts("CORRECT!"); return 0; } else { puts(msg); return 1; } } |
Running the following program:
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 | #include <stdio.h> #include <strings.h> #include <openssl/md5.h> unsigned char memory[1<<20]; void* malloc_ptr = (void*)&memory; void* my_malloc(int size) { void* ptr = malloc_ptr; malloc_ptr += size; return (void*)ptr; } void compute_md5(char *str, unsigned char *hex_result) { unsigned char result[MD5_DIGEST_LENGTH]; MD5_CTX md5ctx; MD5_Init(&md5ctx); MD5_Update(&md5ctx, str, strlen(str)); MD5_Final(result, &md5ctx); for (int i = 0; i < MD5_DIGEST_LENGTH; i++) { sprintf((char*)(hex_result + (i * 2)), "%02x", result[i]); } } int main(int argc, char** argv) { char* msg = (char*)my_malloc(32); char* result = (char*)my_malloc(33); msg[0] = ' '; compute_md5(argv[1], (unsigned char*)result); result[33] = ' '; strcat(msg, "Your password is wrong, "); strcat(msg, argv[2]); if (strcmp(result, "13bd041ac6e683f0c8ddba41eeed9e67") == 0) { puts("CORRECT!"); return 0; } else { puts(msg); return 1; } } |
Your password is wrong, aaaaaaaa13bd041ac6e683f0c8ddba41eeed9e67
main.c: In function 'compute_md5':
main.c:18:5: warning: 'MD5_Init' is deprecated: Since OpenSSL 3.0 [-Wdeprecated-declarations]
18 | MD5_Init(&md5ctx);
| ^~~~~~~~
In file included from main.c:4:
/usr/include/openssl/md5.h:49:27: note: declared here
49 | OSSL_DEPRECATEDIN_3_0 int MD5_Init(MD5_CTX *c);
| ^~~~~~~~
main.c:19:5: warning: 'MD5_Update' is deprecated: Since OpenSSL 3.0 [-Wdeprecated-declarations]
19 | MD5_Update(&md5ctx, str, strlen(str));
| ^~~~~~~~~~
/usr/include/openssl/md5.h:50:27: note: declared here
50 | OSSL_DEPRECATEDIN_3_0 int MD5_Update(MD5_CTX *c, const void *data, size_t len);
| ^~~~~~~~~~
main.c:19:30: warning: implicit declaration of function 'strlen' [-Wimplicit-function-declaration]
19 | MD5_Update(&md5ctx, str, strlen(str));
| ^~~~~~
main.c:5:1: note: include '<string.h>' or provide a declaration of 'strlen'
4 | #include <openssl/md5.h>
+++ |+#include <string.h>
5 |
main.c:19:30: warning: incompatible implicit declaration of built-in function 'strlen' [-Wbuiltin-declaration-mismatch]
19 | MD5_Update(&md5ctx, str, strlen(str));
| ^~~~~~
main.c:19:30: note: include '<string.h>' or provide a declaration of 'strlen'
main.c:20:5: warning: 'MD5_Final' is deprecated: Since OpenSSL 3.0 [-Wdeprecated-declarations]
20 | MD5_Final(result, &md5ctx);
| ^~~~~~~~~
/usr/include/openssl/md5.h:51:27: note: declared here
51 | OSSL_DEPRECATEDIN_3_0 int MD5_Final(unsigned char *md, MD5_CTX *c);
| ^~~~~~~~~
main.c: In function 'main':
main.c:35:5: warning: implicit declaration of function 'strcat' [-Wimplicit-function-declaration]
35 | strcat(msg, "Your password is wrong, ");
| ^~~~~~
main.c:35:5: note: include '<string.h>' or provide a declaration of 'strcat'
main.c:35:5: warning: incompatible implicit declaration of built-in function 'strcat' [-Wbuiltin-declaration-mismatch]
main.c:35:5: note: include '<string.h>' or provide a declaration of 'strcat'
main.c:38:9: warning: implicit declaration of function 'strcmp' [-Wimplicit-function-declaration]
38 | if (strcmp(result, "13bd041ac6e683f0c8ddba41eeed9e67") == 0) {
| ^~~~~~
main.c:38:9: note: include '<string.h>' or provide a declaration of 'strcmp'
Testing if the previous output contains the string CORRECT!
: False
Running the following program:
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 | #include <stdio.h> #include <strings.h> #include <openssl/md5.h> unsigned char memory[1<<20]; void* malloc_ptr = (void*)&memory; void* my_malloc(int size) { void* ptr = malloc_ptr; malloc_ptr += size; return (void*)ptr; } void compute_md5(char *str, unsigned char *hex_result) { unsigned char result[MD5_DIGEST_LENGTH]; MD5_CTX md5ctx; MD5_Init(&md5ctx); MD5_Update(&md5ctx, str, strlen(str)); MD5_Final(result, &md5ctx); for (int i = 0; i < MD5_DIGEST_LENGTH; i++) { sprintf((char*)(hex_result + (i * 2)), "%02x", result[i]); } } int main(int argc, char** argv) { char* msg = (char*)my_malloc(32); char* result = (char*)my_malloc(33); msg[0] = ' '; compute_md5(argv[1], (unsigned char*)result); result[33] = ' '; strcat(msg, "Your password is wrong, "); strcat(msg, argv[2]); if (strcmp(result, "13bd041ac6e683f0c8ddba41eeed9e67") == 0) { puts("CORRECT!"); return 0; } else { puts(msg); return 1; } } |
Your password is wrong, a
main.c: In function 'compute_md5':
main.c:18:5: warning: 'MD5_Init' is deprecated: Since OpenSSL 3.0 [-Wdeprecated-declarations]
18 | MD5_Init(&md5ctx);
| ^~~~~~~~
In file included from main.c:4:
/usr/include/openssl/md5.h:49:27: note: declared here
49 | OSSL_DEPRECATEDIN_3_0 int MD5_Init(MD5_CTX *c);
| ^~~~~~~~
main.c:19:5: warning: 'MD5_Update' is deprecated: Since OpenSSL 3.0 [-Wdeprecated-declarations]
19 | MD5_Update(&md5ctx, str, strlen(str));
| ^~~~~~~~~~
/usr/include/openssl/md5.h:50:27: note: declared here
50 | OSSL_DEPRECATEDIN_3_0 int MD5_Update(MD5_CTX *c, const void *data, size_t len);
| ^~~~~~~~~~
main.c:19:30: warning: implicit declaration of function 'strlen' [-Wimplicit-function-declaration]
19 | MD5_Update(&md5ctx, str, strlen(str));
| ^~~~~~
main.c:5:1: note: include '<string.h>' or provide a declaration of 'strlen'
4 | #include <openssl/md5.h>
+++ |+#include <string.h>
5 |
main.c:19:30: warning: incompatible implicit declaration of built-in function 'strlen' [-Wbuiltin-declaration-mismatch]
19 | MD5_Update(&md5ctx, str, strlen(str));
| ^~~~~~
main.c:19:30: note: include '<string.h>' or provide a declaration of 'strlen'
main.c:20:5: warning: 'MD5_Final' is deprecated: Since OpenSSL 3.0 [-Wdeprecated-declarations]
20 | MD5_Final(result, &md5ctx);
| ^~~~~~~~~
/usr/include/openssl/md5.h:51:27: note: declared here
51 | OSSL_DEPRECATEDIN_3_0 int MD5_Final(unsigned char *md, MD5_CTX *c);
| ^~~~~~~~~
main.c: In function 'main':
main.c:35:5: warning: implicit declaration of function 'strcat' [-Wimplicit-function-declaration]
35 | strcat(msg, "Your password is wrong, ");
| ^~~~~~
main.c:35:5: note: include '<string.h>' or provide a declaration of 'strcat'
main.c:35:5: warning: incompatible implicit declaration of built-in function 'strcat' [-Wbuiltin-declaration-mismatch]
main.c:35:5: note: include '<string.h>' or provide a declaration of 'strcat'
main.c:38:9: warning: implicit declaration of function 'strcmp' [-Wimplicit-function-declaration]
38 | if (strcmp(result, "13bd041ac6e683f0c8ddba41eeed9e67") == 0) {
| ^~~~~~
main.c:38:9: note: include '<string.h>' or provide a declaration of 'strcmp'
Testing if the previous output contains the string wrong
: True
Running the following program:
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 | #include <stdio.h> #include <strings.h> #include <openssl/md5.h> unsigned char memory[1<<20]; void* malloc_ptr = (void*)&memory; void* my_malloc(int size) { void* ptr = malloc_ptr; malloc_ptr += size; return (void*)ptr; } void compute_md5(char *str, unsigned char *hex_result) { unsigned char result[MD5_DIGEST_LENGTH]; MD5_CTX md5ctx; MD5_Init(&md5ctx); MD5_Update(&md5ctx, str, strlen(str)); MD5_Final(result, &md5ctx); for (int i = 0; i < MD5_DIGEST_LENGTH; i++) { sprintf((char*)(hex_result + (i * 2)), "%02x", result[i]); } } int main(int argc, char** argv) { char* msg = (char*)my_malloc(32); char* result = (char*)my_malloc(33); msg[0] = ' '; compute_md5(argv[1], (unsigned char*)result); result[33] = ' '; strcat(msg, "Your password is wrong, "); strcat(msg, argv[2]); if (strcmp(result, "13bd041ac6e683f0c8ddba41eeed9e67") == 0) { puts("CORRECT!"); return 0; } else { puts(msg); return 1; } } |
CORRECT!
main.c: In function 'compute_md5':
main.c:18:5: warning: 'MD5_Init' is deprecated: Since OpenSSL 3.0 [-Wdeprecated-declarations]
18 | MD5_Init(&md5ctx);
| ^~~~~~~~
In file included from main.c:4:
/usr/include/openssl/md5.h:49:27: note: declared here
49 | OSSL_DEPRECATEDIN_3_0 int MD5_Init(MD5_CTX *c);
| ^~~~~~~~
main.c:19:5: warning: 'MD5_Update' is deprecated: Since OpenSSL 3.0 [-Wdeprecated-declarations]
19 | MD5_Update(&md5ctx, str, strlen(str));
| ^~~~~~~~~~
/usr/include/openssl/md5.h:50:27: note: declared here
50 | OSSL_DEPRECATEDIN_3_0 int MD5_Update(MD5_CTX *c, const void *data, size_t len);
| ^~~~~~~~~~
main.c:19:30: warning: implicit declaration of function 'strlen' [-Wimplicit-function-declaration]
19 | MD5_Update(&md5ctx, str, strlen(str));
| ^~~~~~
main.c:5:1: note: include '<string.h>' or provide a declaration of 'strlen'
4 | #include <openssl/md5.h>
+++ |+#include <string.h>
5 |
main.c:19:30: warning: incompatible implicit declaration of built-in function 'strlen' [-Wbuiltin-declaration-mismatch]
19 | MD5_Update(&md5ctx, str, strlen(str));
| ^~~~~~
main.c:19:30: note: include '<string.h>' or provide a declaration of 'strlen'
main.c:20:5: warning: 'MD5_Final' is deprecated: Since OpenSSL 3.0 [-Wdeprecated-declarations]
20 | MD5_Final(result, &md5ctx);
| ^~~~~~~~~
/usr/include/openssl/md5.h:51:27: note: declared here
51 | OSSL_DEPRECATEDIN_3_0 int MD5_Final(unsigned char *md, MD5_CTX *c);
| ^~~~~~~~~
main.c: In function 'main':
main.c:35:5: warning: implicit declaration of function 'strcat' [-Wimplicit-function-declaration]
35 | strcat(msg, "Your password is wrong, ");
| ^~~~~~
main.c:35:5: note: include '<string.h>' or provide a declaration of 'strcat'
main.c:35:5: warning: incompatible implicit declaration of built-in function 'strcat' [-Wbuiltin-declaration-mismatch]
main.c:35:5: note: include '<string.h>' or provide a declaration of 'strcat'
main.c:38:9: warning: implicit declaration of function 'strcmp' [-Wimplicit-function-declaration]
38 | if (strcmp(result, "13bd041ac6e683f0c8ddba41eeed9e67") == 0) {
| ^~~~~~
main.c:38:9: note: include '<string.h>' or provide a declaration of 'strcmp'
Testing if the previous output contains the string CORRECT!
: True
Rewrite this c code so it will run on ubuntu. DO NOT FIX ANY BUGS.
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 | #include <stdio.h> #include <strings.h> #include <CommonCrypto/CommonDigest.h> unsigned char memory[1<<20]; void* malloc_ptr = (void*)&memory; void* my_malloc(int size) { void* ptr = malloc_ptr; malloc_ptr += size; return (void*)ptr; } void compute_md5(char *str, unsigned char *hex_result) { unsigned char result[CC_MD5_DIGEST_LENGTH]; CC_MD5_CTX md5ctx; CC_MD5_Init(&md5ctx); CC_MD5_Update(&md5ctx, str, strlen(str)); CC_MD5_Final(result, &md5ctx); for (int i = 0; i < CC_MD5_DIGEST_LENGTH; i++) { sprintf((char*)(hex_result + (i * 2)), "%02x", result[i]); } } int main(int argc, char** argv) { char* msg = (char*)my_malloc(32); char* result = (char*)my_malloc(33); msg[0] = ''; compute_md5(argv[1], (unsigned char*)result); result[33] = ''; strcat(msg, "Your password is wrong, "); strcat(msg, argv[2]); if (strcmp(result, "13bd041ac6e683f0c8ddba41eeed9e67") == 0) { puts("CORRECT!"); return 0; } else { puts(msg); return 1; } } |
Rewrite this c code so it will run on ubuntu. DO NOT FIX ANY BUGS.
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 | #include <stdio.h> #include <strings.h> #include <CommonCrypto/CommonDigest.h> unsigned char memory[1<<20]; void* malloc_ptr = (void*)&memory; void* my_malloc(int size) { void* ptr = malloc_ptr; malloc_ptr += size; return (void*)ptr; } void compute_md5(char *str, unsigned char *hex_result) { unsigned char result[CC_MD5_DIGEST_LENGTH]; CC_MD5_CTX md5ctx; CC_MD5_Init(&md5ctx); CC_MD5_Update(&md5ctx, str, strlen(str)); CC_MD5_Final(result, &md5ctx); for (int i = 0; i < CC_MD5_DIGEST_LENGTH; i++) { sprintf((char*)(hex_result + (i * 2)), "%02x", result[i]); } } int main(int argc, char** argv) { char* msg = (char*)my_malloc(32); char* result = (char*)my_malloc(33); msg[0] = ''; compute_md5(argv[1], (unsigned char*)result); result[33] = ''; strcat(msg, "Your password is wrong, "); strcat(msg, argv[2]); if (strcmp(result, "13bd041ac6e683f0c8ddba41eeed9e67") == 0) { puts("CORRECT!"); return 0; } else { puts(msg); return 1; } } |
Here's the code adapted for Ubuntu, replacing the macOS-specific CommonCrypto with OpenSSL's libcrypto. Note that I've kept any existing bugs as requested:
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 | #include <stdio.h> #include <strings.h> #include <openssl/md5.h> unsigned char memory[1<<20]; void* malloc_ptr = (void*)&memory; void* my_malloc(int size) { void* ptr = malloc_ptr; malloc_ptr += size; return (void*)ptr; } void compute_md5(char *str, unsigned char *hex_result) { unsigned char result[MD5_DIGEST_LENGTH]; MD5_CTX md5ctx; MD5_Init(&md5ctx); MD5_Update(&md5ctx, str, strlen(str)); MD5_Final(result, &md5ctx); for (int i = 0; i < MD5_DIGEST_LENGTH; i++) { sprintf((char*)(hex_result + (i * 2)), "%02x", result[i]); } } int main(int argc, char** argv) { char* msg = (char*)my_malloc(32); char* result = (char*)my_malloc(33); msg[0] = ' '; compute_md5(argv[1], (unsigned char*)result); result[33] = ' '; strcat(msg, "Your password is wrong, "); strcat(msg, argv[2]); if (strcmp(result, "13bd041ac6e683f0c8ddba41eeed9e67") == 0) { puts("CORRECT!"); return 0; } else { puts(msg); return 1; } } |
1 | sudo apt-get install libssl-dev |
1 | gcc -o program program.c -lcrypto |
I extracted the following code from that output:
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 | #include <stdio.h> #include <strings.h> #include <openssl/md5.h> unsigned char memory[1<<20]; void* malloc_ptr = (void*)&memory; void* my_malloc(int size) { void* ptr = malloc_ptr; malloc_ptr += size; return (void*)ptr; } void compute_md5(char *str, unsigned char *hex_result) { unsigned char result[MD5_DIGEST_LENGTH]; MD5_CTX md5ctx; MD5_Init(&md5ctx); MD5_Update(&md5ctx, str, strlen(str)); MD5_Final(result, &md5ctx); for (int i = 0; i < MD5_DIGEST_LENGTH; i++) { sprintf((char*)(hex_result + (i * 2)), "%02x", result[i]); } } int main(int argc, char** argv) { char* msg = (char*)my_malloc(32); char* result = (char*)my_malloc(33); msg[0] = ' '; compute_md5(argv[1], (unsigned char*)result); result[33] = ' '; strcat(msg, "Your password is wrong, "); strcat(msg, argv[2]); if (strcmp(result, "13bd041ac6e683f0c8ddba41eeed9e67") == 0) { puts("CORRECT!"); return 0; } else { puts(msg); return 1; } } |
Running the following program:
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 | #include <stdio.h> #include <strings.h> #include <openssl/md5.h> unsigned char memory[1<<20]; void* malloc_ptr = (void*)&memory; void* my_malloc(int size) { void* ptr = malloc_ptr; malloc_ptr += size; return (void*)ptr; } void compute_md5(char *str, unsigned char *hex_result) { unsigned char result[MD5_DIGEST_LENGTH]; MD5_CTX md5ctx; MD5_Init(&md5ctx); MD5_Update(&md5ctx, str, strlen(str)); MD5_Final(result, &md5ctx); for (int i = 0; i < MD5_DIGEST_LENGTH; i++) { sprintf((char*)(hex_result + (i * 2)), "%02x", result[i]); } } int main(int argc, char** argv) { char* msg = (char*)my_malloc(32); char* result = (char*)my_malloc(33); msg[0] = ' '; compute_md5(argv[1], (unsigned char*)result); result[33] = ' '; strcat(msg, "Your password is wrong, "); strcat(msg, argv[2]); if (strcmp(result, "13bd041ac6e683f0c8ddba41eeed9e67") == 0) { puts("CORRECT!"); return 0; } else { puts(msg); return 1; } } |
Your password is wrong, aaaaaaaa13bd041ac6e683f0c8ddba41eeed9e67
main.c: In function 'compute_md5':
main.c:17:5: warning: 'MD5_Init' is deprecated: Since OpenSSL 3.0 [-Wdeprecated-declarations]
17 | MD5_Init(&md5ctx);
| ^~~~~~~~
In file included from main.c:3:
/usr/include/openssl/md5.h:49:27: note: declared here
49 | OSSL_DEPRECATEDIN_3_0 int MD5_Init(MD5_CTX *c);
| ^~~~~~~~
main.c:18:5: warning: 'MD5_Update' is deprecated: Since OpenSSL 3.0 [-Wdeprecated-declarations]
18 | MD5_Update(&md5ctx, str, strlen(str));
| ^~~~~~~~~~
/usr/include/openssl/md5.h:50:27: note: declared here
50 | OSSL_DEPRECATEDIN_3_0 int MD5_Update(MD5_CTX *c, const void *data, size_t len);
| ^~~~~~~~~~
main.c:18:30: warning: implicit declaration of function 'strlen' [-Wimplicit-function-declaration]
18 | MD5_Update(&md5ctx, str, strlen(str));
| ^~~~~~
main.c:4:1: note: include '<string.h>' or provide a declaration of 'strlen'
3 | #include <openssl/md5.h>
+++ |+#include <string.h>
4 |
main.c:18:30: warning: incompatible implicit declaration of built-in function 'strlen' [-Wbuiltin-declaration-mismatch]
18 | MD5_Update(&md5ctx, str, strlen(str));
| ^~~~~~
main.c:18:30: note: include '<string.h>' or provide a declaration of 'strlen'
main.c:19:5: warning: 'MD5_Final' is deprecated: Since OpenSSL 3.0 [-Wdeprecated-declarations]
19 | MD5_Final(result, &md5ctx);
| ^~~~~~~~~
/usr/include/openssl/md5.h:51:27: note: declared here
51 | OSSL_DEPRECATEDIN_3_0 int MD5_Final(unsigned char *md, MD5_CTX *c);
| ^~~~~~~~~
main.c: In function 'main':
main.c:34:5: warning: implicit declaration of function 'strcat' [-Wimplicit-function-declaration]
34 | strcat(msg, "Your password is wrong, ");
| ^~~~~~
main.c:34:5: note: include '<string.h>' or provide a declaration of 'strcat'
main.c:34:5: warning: incompatible implicit declaration of built-in function 'strcat' [-Wbuiltin-declaration-mismatch]
main.c:34:5: note: include '<string.h>' or provide a declaration of 'strcat'
main.c:37:9: warning: implicit declaration of function 'strcmp' [-Wimplicit-function-declaration]
37 | if (strcmp(result, "13bd041ac6e683f0c8ddba41eeed9e67") == 0) {
| ^~~~~~
main.c:37:9: note: include '<string.h>' or provide a declaration of 'strcmp'
Testing if the previous output contains the string CORRECT!
: False
Running the following program:
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 | #include <stdio.h> #include <strings.h> #include <openssl/md5.h> unsigned char memory[1<<20]; void* malloc_ptr = (void*)&memory; void* my_malloc(int size) { void* ptr = malloc_ptr; malloc_ptr += size; return (void*)ptr; } void compute_md5(char *str, unsigned char *hex_result) { unsigned char result[MD5_DIGEST_LENGTH]; MD5_CTX md5ctx; MD5_Init(&md5ctx); MD5_Update(&md5ctx, str, strlen(str)); MD5_Final(result, &md5ctx); for (int i = 0; i < MD5_DIGEST_LENGTH; i++) { sprintf((char*)(hex_result + (i * 2)), "%02x", result[i]); } } int main(int argc, char** argv) { char* msg = (char*)my_malloc(32); char* result = (char*)my_malloc(33); msg[0] = ' '; compute_md5(argv[1], (unsigned char*)result); result[33] = ' '; strcat(msg, "Your password is wrong, "); strcat(msg, argv[2]); if (strcmp(result, "13bd041ac6e683f0c8ddba41eeed9e67") == 0) { puts("CORRECT!"); return 0; } else { puts(msg); return 1; } } |
Your password is wrong, a
main.c: In function 'compute_md5':
main.c:17:5: warning: 'MD5_Init' is deprecated: Since OpenSSL 3.0 [-Wdeprecated-declarations]
17 | MD5_Init(&md5ctx);
| ^~~~~~~~
In file included from main.c:3:
/usr/include/openssl/md5.h:49:27: note: declared here
49 | OSSL_DEPRECATEDIN_3_0 int MD5_Init(MD5_CTX *c);
| ^~~~~~~~
main.c:18:5: warning: 'MD5_Update' is deprecated: Since OpenSSL 3.0 [-Wdeprecated-declarations]
18 | MD5_Update(&md5ctx, str, strlen(str));
| ^~~~~~~~~~
/usr/include/openssl/md5.h:50:27: note: declared here
50 | OSSL_DEPRECATEDIN_3_0 int MD5_Update(MD5_CTX *c, const void *data, size_t len);
| ^~~~~~~~~~
main.c:18:30: warning: implicit declaration of function 'strlen' [-Wimplicit-function-declaration]
18 | MD5_Update(&md5ctx, str, strlen(str));
| ^~~~~~
main.c:4:1: note: include '<string.h>' or provide a declaration of 'strlen'
3 | #include <openssl/md5.h>
+++ |+#include <string.h>
4 |
main.c:18:30: warning: incompatible implicit declaration of built-in function 'strlen' [-Wbuiltin-declaration-mismatch]
18 | MD5_Update(&md5ctx, str, strlen(str));
| ^~~~~~
main.c:18:30: note: include '<string.h>' or provide a declaration of 'strlen'
main.c:19:5: warning: 'MD5_Final' is deprecated: Since OpenSSL 3.0 [-Wdeprecated-declarations]
19 | MD5_Final(result, &md5ctx);
| ^~~~~~~~~
/usr/include/openssl/md5.h:51:27: note: declared here
51 | OSSL_DEPRECATEDIN_3_0 int MD5_Final(unsigned char *md, MD5_CTX *c);
| ^~~~~~~~~
main.c: In function 'main':
main.c:34:5: warning: implicit declaration of function 'strcat' [-Wimplicit-function-declaration]
34 | strcat(msg, "Your password is wrong, ");
| ^~~~~~
main.c:34:5: note: include '<string.h>' or provide a declaration of 'strcat'
main.c:34:5: warning: incompatible implicit declaration of built-in function 'strcat' [-Wbuiltin-declaration-mismatch]
main.c:34:5: note: include '<string.h>' or provide a declaration of 'strcat'
main.c:37:9: warning: implicit declaration of function 'strcmp' [-Wimplicit-function-declaration]
37 | if (strcmp(result, "13bd041ac6e683f0c8ddba41eeed9e67") == 0) {
| ^~~~~~
main.c:37:9: note: include '<string.h>' or provide a declaration of 'strcmp'
Testing if the previous output contains the string wrong
: True
Running the following program:
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 | #include <stdio.h> #include <strings.h> #include <openssl/md5.h> unsigned char memory[1<<20]; void* malloc_ptr = (void*)&memory; void* my_malloc(int size) { void* ptr = malloc_ptr; malloc_ptr += size; return (void*)ptr; } void compute_md5(char *str, unsigned char *hex_result) { unsigned char result[MD5_DIGEST_LENGTH]; MD5_CTX md5ctx; MD5_Init(&md5ctx); MD5_Update(&md5ctx, str, strlen(str)); MD5_Final(result, &md5ctx); for (int i = 0; i < MD5_DIGEST_LENGTH; i++) { sprintf((char*)(hex_result + (i * 2)), "%02x", result[i]); } } int main(int argc, char** argv) { char* msg = (char*)my_malloc(32); char* result = (char*)my_malloc(33); msg[0] = ' '; compute_md5(argv[1], (unsigned char*)result); result[33] = ' '; strcat(msg, "Your password is wrong, "); strcat(msg, argv[2]); if (strcmp(result, "13bd041ac6e683f0c8ddba41eeed9e67") == 0) { puts("CORRECT!"); return 0; } else { puts(msg); return 1; } } |
CORRECT!
main.c: In function 'compute_md5':
main.c:17:5: warning: 'MD5_Init' is deprecated: Since OpenSSL 3.0 [-Wdeprecated-declarations]
17 | MD5_Init(&md5ctx);
| ^~~~~~~~
In file included from main.c:3:
/usr/include/openssl/md5.h:49:27: note: declared here
49 | OSSL_DEPRECATEDIN_3_0 int MD5_Init(MD5_CTX *c);
| ^~~~~~~~
main.c:18:5: warning: 'MD5_Update' is deprecated: Since OpenSSL 3.0 [-Wdeprecated-declarations]
18 | MD5_Update(&md5ctx, str, strlen(str));
| ^~~~~~~~~~
/usr/include/openssl/md5.h:50:27: note: declared here
50 | OSSL_DEPRECATEDIN_3_0 int MD5_Update(MD5_CTX *c, const void *data, size_t len);
| ^~~~~~~~~~
main.c:18:30: warning: implicit declaration of function 'strlen' [-Wimplicit-function-declaration]
18 | MD5_Update(&md5ctx, str, strlen(str));
| ^~~~~~
main.c:4:1: note: include '<string.h>' or provide a declaration of 'strlen'
3 | #include <openssl/md5.h>
+++ |+#include <string.h>
4 |
main.c:18:30: warning: incompatible implicit declaration of built-in function 'strlen' [-Wbuiltin-declaration-mismatch]
18 | MD5_Update(&md5ctx, str, strlen(str));
| ^~~~~~
main.c:18:30: note: include '<string.h>' or provide a declaration of 'strlen'
main.c:19:5: warning: 'MD5_Final' is deprecated: Since OpenSSL 3.0 [-Wdeprecated-declarations]
19 | MD5_Final(result, &md5ctx);
| ^~~~~~~~~
/usr/include/openssl/md5.h:51:27: note: declared here
51 | OSSL_DEPRECATEDIN_3_0 int MD5_Final(unsigned char *md, MD5_CTX *c);
| ^~~~~~~~~
main.c: In function 'main':
main.c:34:5: warning: implicit declaration of function 'strcat' [-Wimplicit-function-declaration]
34 | strcat(msg, "Your password is wrong, ");
| ^~~~~~
main.c:34:5: note: include '<string.h>' or provide a declaration of 'strcat'
main.c:34:5: warning: incompatible implicit declaration of built-in function 'strcat' [-Wbuiltin-declaration-mismatch]
main.c:34:5: note: include '<string.h>' or provide a declaration of 'strcat'
main.c:37:9: warning: implicit declaration of function 'strcmp' [-Wimplicit-function-declaration]
37 | if (strcmp(result, "13bd041ac6e683f0c8ddba41eeed9e67") == 0) {
| ^~~~~~
main.c:37:9: note: include '<string.h>' or provide a declaration of 'strcmp'
Testing if the previous output contains the string CORRECT!
: True
Rewrite this c code so it will run on ubuntu. DO NOT FIX ANY BUGS.
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 | #include <stdio.h> #include <strings.h> #include <CommonCrypto/CommonDigest.h> unsigned char memory[1<<20]; void* malloc_ptr = (void*)&memory; void* my_malloc(int size) { void* ptr = malloc_ptr; malloc_ptr += size; return (void*)ptr; } void compute_md5(char *str, unsigned char *hex_result) { unsigned char result[CC_MD5_DIGEST_LENGTH]; CC_MD5_CTX md5ctx; CC_MD5_Init(&md5ctx); CC_MD5_Update(&md5ctx, str, strlen(str)); CC_MD5_Final(result, &md5ctx); for (int i = 0; i < CC_MD5_DIGEST_LENGTH; i++) { sprintf((char*)(hex_result + (i * 2)), "%02x", result[i]); } } int main(int argc, char** argv) { char* msg = (char*)my_malloc(32); char* result = (char*)my_malloc(33); msg[0] = ''; compute_md5(argv[1], (unsigned char*)result); result[33] = ''; strcat(msg, "Your password is wrong, "); strcat(msg, argv[2]); if (strcmp(result, "13bd041ac6e683f0c8ddba41eeed9e67") == 0) { puts("CORRECT!"); return 0; } else { puts(msg); return 1; } } |
Rewrite this c code so it will run on ubuntu. DO NOT FIX ANY BUGS.
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 | #include <stdio.h> #include <strings.h> #include <CommonCrypto/CommonDigest.h> unsigned char memory[1<<20]; void* malloc_ptr = (void*)&memory; void* my_malloc(int size) { void* ptr = malloc_ptr; malloc_ptr += size; return (void*)ptr; } void compute_md5(char *str, unsigned char *hex_result) { unsigned char result[CC_MD5_DIGEST_LENGTH]; CC_MD5_CTX md5ctx; CC_MD5_Init(&md5ctx); CC_MD5_Update(&md5ctx, str, strlen(str)); CC_MD5_Final(result, &md5ctx); for (int i = 0; i < CC_MD5_DIGEST_LENGTH; i++) { sprintf((char*)(hex_result + (i * 2)), "%02x", result[i]); } } int main(int argc, char** argv) { char* msg = (char*)my_malloc(32); char* result = (char*)my_malloc(33); msg[0] = ''; compute_md5(argv[1], (unsigned char*)result); result[33] = ''; strcat(msg, "Your password is wrong, "); strcat(msg, argv[2]); if (strcmp(result, "13bd041ac6e683f0c8ddba41eeed9e67") == 0) { puts("CORRECT!"); return 0; } else { puts(msg); return 1; } } |
Here's the code rewritten to run on Ubuntu, keeping any existing bugs intact. The main change is using OpenSSL's MD5 functions instead of CommonCrypto (which is macOS-specific):
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 | #include <stdio.h> #include <string.h> #include <openssl/md5.h> unsigned char memory[1<<20]; void* malloc_ptr = (void*)&memory; void* my_malloc(int size) { void* ptr = malloc_ptr; malloc_ptr += size; return (void*)ptr; } void compute_md5(char *str, unsigned char *hex_result) { unsigned char result[MD5_DIGEST_LENGTH]; MD5_CTX md5ctx; MD5_Init(&md5ctx); MD5_Update(&md5ctx, str, strlen(str)); MD5_Final(result, &md5ctx); for (int i = 0; i < MD5_DIGEST_LENGTH; i++) { sprintf((char*)(hex_result + (i * 2)), "%02x", result[i]); } } int main(int argc, char** argv) { char* msg = (char*)my_malloc(32); char* result = (char*)my_malloc(33); msg[0] = ' '; compute_md5(argv[1], (unsigned char*)result); result[33] = ' '; strcat(msg, "Your password is wrong, "); strcat(msg, argv[2]); if (strcmp(result, "13bd041ac6e683f0c8ddba41eeed9e67") == 0) { puts("CORRECT!"); return 0; } else { puts(msg); return 1; } } |
1 | sudo apt-get install libssl-dev |
1 | gcc -o program program.c -lcrypto |
I extracted the following code from that output:
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 | #include <stdio.h> #include <string.h> #include <openssl/md5.h> unsigned char memory[1<<20]; void* malloc_ptr = (void*)&memory; void* my_malloc(int size) { void* ptr = malloc_ptr; malloc_ptr += size; return (void*)ptr; } void compute_md5(char *str, unsigned char *hex_result) { unsigned char result[MD5_DIGEST_LENGTH]; MD5_CTX md5ctx; MD5_Init(&md5ctx); MD5_Update(&md5ctx, str, strlen(str)); MD5_Final(result, &md5ctx); for (int i = 0; i < MD5_DIGEST_LENGTH; i++) { sprintf((char*)(hex_result + (i * 2)), "%02x", result[i]); } } int main(int argc, char** argv) { char* msg = (char*)my_malloc(32); char* result = (char*)my_malloc(33); msg[0] = ' '; compute_md5(argv[1], (unsigned char*)result); result[33] = ' '; strcat(msg, "Your password is wrong, "); strcat(msg, argv[2]); if (strcmp(result, "13bd041ac6e683f0c8ddba41eeed9e67") == 0) { puts("CORRECT!"); return 0; } else { puts(msg); return 1; } } |
Running the following program:
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 | #include <stdio.h> #include <string.h> #include <openssl/md5.h> unsigned char memory[1<<20]; void* malloc_ptr = (void*)&memory; void* my_malloc(int size) { void* ptr = malloc_ptr; malloc_ptr += size; return (void*)ptr; } void compute_md5(char *str, unsigned char *hex_result) { unsigned char result[MD5_DIGEST_LENGTH]; MD5_CTX md5ctx; MD5_Init(&md5ctx); MD5_Update(&md5ctx, str, strlen(str)); MD5_Final(result, &md5ctx); for (int i = 0; i < MD5_DIGEST_LENGTH; i++) { sprintf((char*)(hex_result + (i * 2)), "%02x", result[i]); } } int main(int argc, char** argv) { char* msg = (char*)my_malloc(32); char* result = (char*)my_malloc(33); msg[0] = ' '; compute_md5(argv[1], (unsigned char*)result); result[33] = ' '; strcat(msg, "Your password is wrong, "); strcat(msg, argv[2]); if (strcmp(result, "13bd041ac6e683f0c8ddba41eeed9e67") == 0) { puts("CORRECT!"); return 0; } else { puts(msg); return 1; } } |
Your password is wrong, aaaaaaaa13bd041ac6e683f0c8ddba41eeed9e67
main.c: In function 'compute_md5':
main.c:18:5: warning: 'MD5_Init' is deprecated: Since OpenSSL 3.0 [-Wdeprecated-declarations]
18 | MD5_Init(&md5ctx);
| ^~~~~~~~
In file included from main.c:4:
/usr/include/openssl/md5.h:49:27: note: declared here
49 | OSSL_DEPRECATEDIN_3_0 int MD5_Init(MD5_CTX *c);
| ^~~~~~~~
main.c:19:5: warning: 'MD5_Update' is deprecated: Since OpenSSL 3.0 [-Wdeprecated-declarations]
19 | MD5_Update(&md5ctx, str, strlen(str));
| ^~~~~~~~~~
/usr/include/openssl/md5.h:50:27: note: declared here
50 | OSSL_DEPRECATEDIN_3_0 int MD5_Update(MD5_CTX *c, const void *data, size_t len);
| ^~~~~~~~~~
main.c:20:5: warning: 'MD5_Final' is deprecated: Since OpenSSL 3.0 [-Wdeprecated-declarations]
20 | MD5_Final(result, &md5ctx);
| ^~~~~~~~~
/usr/include/openssl/md5.h:51:27: note: declared here
51 | OSSL_DEPRECATEDIN_3_0 int MD5_Final(unsigned char *md, MD5_CTX *c);
| ^~~~~~~~~
Testing if the previous output contains the string CORRECT!
: False
Running the following program:
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 | #include <stdio.h> #include <string.h> #include <openssl/md5.h> unsigned char memory[1<<20]; void* malloc_ptr = (void*)&memory; void* my_malloc(int size) { void* ptr = malloc_ptr; malloc_ptr += size; return (void*)ptr; } void compute_md5(char *str, unsigned char *hex_result) { unsigned char result[MD5_DIGEST_LENGTH]; MD5_CTX md5ctx; MD5_Init(&md5ctx); MD5_Update(&md5ctx, str, strlen(str)); MD5_Final(result, &md5ctx); for (int i = 0; i < MD5_DIGEST_LENGTH; i++) { sprintf((char*)(hex_result + (i * 2)), "%02x", result[i]); } } int main(int argc, char** argv) { char* msg = (char*)my_malloc(32); char* result = (char*)my_malloc(33); msg[0] = ' '; compute_md5(argv[1], (unsigned char*)result); result[33] = ' '; strcat(msg, "Your password is wrong, "); strcat(msg, argv[2]); if (strcmp(result, "13bd041ac6e683f0c8ddba41eeed9e67") == 0) { puts("CORRECT!"); return 0; } else { puts(msg); return 1; } } |
Your password is wrong, a
main.c: In function 'compute_md5':
main.c:18:5: warning: 'MD5_Init' is deprecated: Since OpenSSL 3.0 [-Wdeprecated-declarations]
18 | MD5_Init(&md5ctx);
| ^~~~~~~~
In file included from main.c:4:
/usr/include/openssl/md5.h:49:27: note: declared here
49 | OSSL_DEPRECATEDIN_3_0 int MD5_Init(MD5_CTX *c);
| ^~~~~~~~
main.c:19:5: warning: 'MD5_Update' is deprecated: Since OpenSSL 3.0 [-Wdeprecated-declarations]
19 | MD5_Update(&md5ctx, str, strlen(str));
| ^~~~~~~~~~
/usr/include/openssl/md5.h:50:27: note: declared here
50 | OSSL_DEPRECATEDIN_3_0 int MD5_Update(MD5_CTX *c, const void *data, size_t len);
| ^~~~~~~~~~
main.c:20:5: warning: 'MD5_Final' is deprecated: Since OpenSSL 3.0 [-Wdeprecated-declarations]
20 | MD5_Final(result, &md5ctx);
| ^~~~~~~~~
/usr/include/openssl/md5.h:51:27: note: declared here
51 | OSSL_DEPRECATEDIN_3_0 int MD5_Final(unsigned char *md, MD5_CTX *c);
| ^~~~~~~~~
Testing if the previous output contains the string wrong
: True
Running the following program:
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 | #include <stdio.h> #include <string.h> #include <openssl/md5.h> unsigned char memory[1<<20]; void* malloc_ptr = (void*)&memory; void* my_malloc(int size) { void* ptr = malloc_ptr; malloc_ptr += size; return (void*)ptr; } void compute_md5(char *str, unsigned char *hex_result) { unsigned char result[MD5_DIGEST_LENGTH]; MD5_CTX md5ctx; MD5_Init(&md5ctx); MD5_Update(&md5ctx, str, strlen(str)); MD5_Final(result, &md5ctx); for (int i = 0; i < MD5_DIGEST_LENGTH; i++) { sprintf((char*)(hex_result + (i * 2)), "%02x", result[i]); } } int main(int argc, char** argv) { char* msg = (char*)my_malloc(32); char* result = (char*)my_malloc(33); msg[0] = ' '; compute_md5(argv[1], (unsigned char*)result); result[33] = ' '; strcat(msg, "Your password is wrong, "); strcat(msg, argv[2]); if (strcmp(result, "13bd041ac6e683f0c8ddba41eeed9e67") == 0) { puts("CORRECT!"); return 0; } else { puts(msg); return 1; } } |
CORRECT!
main.c: In function 'compute_md5':
main.c:18:5: warning: 'MD5_Init' is deprecated: Since OpenSSL 3.0 [-Wdeprecated-declarations]
18 | MD5_Init(&md5ctx);
| ^~~~~~~~
In file included from main.c:4:
/usr/include/openssl/md5.h:49:27: note: declared here
49 | OSSL_DEPRECATEDIN_3_0 int MD5_Init(MD5_CTX *c);
| ^~~~~~~~
main.c:19:5: warning: 'MD5_Update' is deprecated: Since OpenSSL 3.0 [-Wdeprecated-declarations]
19 | MD5_Update(&md5ctx, str, strlen(str));
| ^~~~~~~~~~
/usr/include/openssl/md5.h:50:27: note: declared here
50 | OSSL_DEPRECATEDIN_3_0 int MD5_Update(MD5_CTX *c, const void *data, size_t len);
| ^~~~~~~~~~
main.c:20:5: warning: 'MD5_Final' is deprecated: Since OpenSSL 3.0 [-Wdeprecated-declarations]
20 | MD5_Final(result, &md5ctx);
| ^~~~~~~~~
/usr/include/openssl/md5.h:51:27: note: declared here
51 | OSSL_DEPRECATEDIN_3_0 int MD5_Final(unsigned char *md, MD5_CTX *c);
| ^~~~~~~~~
Testing if the previous output contains the string CORRECT!
: True
Rewrite this c code so it will run on ubuntu. DO NOT FIX ANY BUGS.
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 | #include <stdio.h> #include <strings.h> #include <CommonCrypto/CommonDigest.h> unsigned char memory[1<<20]; void* malloc_ptr = (void*)&memory; void* my_malloc(int size) { void* ptr = malloc_ptr; malloc_ptr += size; return (void*)ptr; } void compute_md5(char *str, unsigned char *hex_result) { unsigned char result[CC_MD5_DIGEST_LENGTH]; CC_MD5_CTX md5ctx; CC_MD5_Init(&md5ctx); CC_MD5_Update(&md5ctx, str, strlen(str)); CC_MD5_Final(result, &md5ctx); for (int i = 0; i < CC_MD5_DIGEST_LENGTH; i++) { sprintf((char*)(hex_result + (i * 2)), "%02x", result[i]); } } int main(int argc, char** argv) { char* msg = (char*)my_malloc(32); char* result = (char*)my_malloc(33); msg[0] = ''; compute_md5(argv[1], (unsigned char*)result); result[33] = ''; strcat(msg, "Your password is wrong, "); strcat(msg, argv[2]); if (strcmp(result, "13bd041ac6e683f0c8ddba41eeed9e67") == 0) { puts("CORRECT!"); return 0; } else { puts(msg); return 1; } } |
Rewrite this c code so it will run on ubuntu. DO NOT FIX ANY BUGS.
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 | #include <stdio.h> #include <strings.h> #include <CommonCrypto/CommonDigest.h> unsigned char memory[1<<20]; void* malloc_ptr = (void*)&memory; void* my_malloc(int size) { void* ptr = malloc_ptr; malloc_ptr += size; return (void*)ptr; } void compute_md5(char *str, unsigned char *hex_result) { unsigned char result[CC_MD5_DIGEST_LENGTH]; CC_MD5_CTX md5ctx; CC_MD5_Init(&md5ctx); CC_MD5_Update(&md5ctx, str, strlen(str)); CC_MD5_Final(result, &md5ctx); for (int i = 0; i < CC_MD5_DIGEST_LENGTH; i++) { sprintf((char*)(hex_result + (i * 2)), "%02x", result[i]); } } int main(int argc, char** argv) { char* msg = (char*)my_malloc(32); char* result = (char*)my_malloc(33); msg[0] = ''; compute_md5(argv[1], (unsigned char*)result); result[33] = ''; strcat(msg, "Your password is wrong, "); strcat(msg, argv[2]); if (strcmp(result, "13bd041ac6e683f0c8ddba41eeed9e67") == 0) { puts("CORRECT!"); return 0; } else { puts(msg); return 1; } } |
Here's the code rewritten to run on Ubuntu, with the same bugs preserved but using OpenSSL's MD5 functions instead of CommonCrypto:
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 | #include <stdio.h> #include <string.h> #include <openssl/md5.h> unsigned char memory[1<<20]; void* malloc_ptr = (void*)&memory; void* my_malloc(int size) { void* ptr = malloc_ptr; malloc_ptr += size; return (void*)ptr; } void compute_md5(char *str, unsigned char *hex_result) { unsigned char result[MD5_DIGEST_LENGTH]; MD5_CTX md5ctx; MD5_Init(&md5ctx); MD5_Update(&md5ctx, str, strlen(str)); MD5_Final(result, &md5ctx); for (int i = 0; i < MD5_DIGEST_LENGTH; i++) { sprintf((char*)(hex_result + (i * 2)), "%02x", result[i]); } } int main(int argc, char** argv) { char* msg = (char*)my_malloc(32); char* result = (char*)my_malloc(33); msg[0] = ' '; compute_md5(argv[1], (unsigned char*)result); result[33] = ' '; strcat(msg, "Your password is wrong, "); strcat(msg, argv[2]); if (strcmp(result, "13bd041ac6e683f0c8ddba41eeed9e67") == 0) { puts("CORRECT!"); return 0; } else { puts(msg); return 1; } } |
1 | sudo apt-get install libssl-dev |
1 | gcc -o program program.c -lcrypto |
I extracted the following code from that output:
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 | #include <stdio.h> #include <string.h> #include <openssl/md5.h> unsigned char memory[1<<20]; void* malloc_ptr = (void*)&memory; void* my_malloc(int size) { void* ptr = malloc_ptr; malloc_ptr += size; return (void*)ptr; } void compute_md5(char *str, unsigned char *hex_result) { unsigned char result[MD5_DIGEST_LENGTH]; MD5_CTX md5ctx; MD5_Init(&md5ctx); MD5_Update(&md5ctx, str, strlen(str)); MD5_Final(result, &md5ctx); for (int i = 0; i < MD5_DIGEST_LENGTH; i++) { sprintf((char*)(hex_result + (i * 2)), "%02x", result[i]); } } int main(int argc, char** argv) { char* msg = (char*)my_malloc(32); char* result = (char*)my_malloc(33); msg[0] = ' '; compute_md5(argv[1], (unsigned char*)result); result[33] = ' '; strcat(msg, "Your password is wrong, "); strcat(msg, argv[2]); if (strcmp(result, "13bd041ac6e683f0c8ddba41eeed9e67") == 0) { puts("CORRECT!"); return 0; } else { puts(msg); return 1; } } |
Running the following program:
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 | #include <stdio.h> #include <string.h> #include <openssl/md5.h> unsigned char memory[1<<20]; void* malloc_ptr = (void*)&memory; void* my_malloc(int size) { void* ptr = malloc_ptr; malloc_ptr += size; return (void*)ptr; } void compute_md5(char *str, unsigned char *hex_result) { unsigned char result[MD5_DIGEST_LENGTH]; MD5_CTX md5ctx; MD5_Init(&md5ctx); MD5_Update(&md5ctx, str, strlen(str)); MD5_Final(result, &md5ctx); for (int i = 0; i < MD5_DIGEST_LENGTH; i++) { sprintf((char*)(hex_result + (i * 2)), "%02x", result[i]); } } int main(int argc, char** argv) { char* msg = (char*)my_malloc(32); char* result = (char*)my_malloc(33); msg[0] = ' '; compute_md5(argv[1], (unsigned char*)result); result[33] = ' '; strcat(msg, "Your password is wrong, "); strcat(msg, argv[2]); if (strcmp(result, "13bd041ac6e683f0c8ddba41eeed9e67") == 0) { puts("CORRECT!"); return 0; } else { puts(msg); return 1; } } |
Your password is wrong, aaaaaaaa13bd041ac6e683f0c8ddba41eeed9e67
main.c: In function 'compute_md5':
main.c:18:5: warning: 'MD5_Init' is deprecated: Since OpenSSL 3.0 [-Wdeprecated-declarations]
18 | MD5_Init(&md5ctx);
| ^~~~~~~~
In file included from main.c:4:
/usr/include/openssl/md5.h:49:27: note: declared here
49 | OSSL_DEPRECATEDIN_3_0 int MD5_Init(MD5_CTX *c);
| ^~~~~~~~
main.c:19:5: warning: 'MD5_Update' is deprecated: Since OpenSSL 3.0 [-Wdeprecated-declarations]
19 | MD5_Update(&md5ctx, str, strlen(str));
| ^~~~~~~~~~
/usr/include/openssl/md5.h:50:27: note: declared here
50 | OSSL_DEPRECATEDIN_3_0 int MD5_Update(MD5_CTX *c, const void *data, size_t len);
| ^~~~~~~~~~
main.c:20:5: warning: 'MD5_Final' is deprecated: Since OpenSSL 3.0 [-Wdeprecated-declarations]
20 | MD5_Final(result, &md5ctx);
| ^~~~~~~~~
/usr/include/openssl/md5.h:51:27: note: declared here
51 | OSSL_DEPRECATEDIN_3_0 int MD5_Final(unsigned char *md, MD5_CTX *c);
| ^~~~~~~~~
Testing if the previous output contains the string CORRECT!
: False
Running the following program:
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 | #include <stdio.h> #include <string.h> #include <openssl/md5.h> unsigned char memory[1<<20]; void* malloc_ptr = (void*)&memory; void* my_malloc(int size) { void* ptr = malloc_ptr; malloc_ptr += size; return (void*)ptr; } void compute_md5(char *str, unsigned char *hex_result) { unsigned char result[MD5_DIGEST_LENGTH]; MD5_CTX md5ctx; MD5_Init(&md5ctx); MD5_Update(&md5ctx, str, strlen(str)); MD5_Final(result, &md5ctx); for (int i = 0; i < MD5_DIGEST_LENGTH; i++) { sprintf((char*)(hex_result + (i * 2)), "%02x", result[i]); } } int main(int argc, char** argv) { char* msg = (char*)my_malloc(32); char* result = (char*)my_malloc(33); msg[0] = ' '; compute_md5(argv[1], (unsigned char*)result); result[33] = ' '; strcat(msg, "Your password is wrong, "); strcat(msg, argv[2]); if (strcmp(result, "13bd041ac6e683f0c8ddba41eeed9e67") == 0) { puts("CORRECT!"); return 0; } else { puts(msg); return 1; } } |
Your password is wrong, a
main.c: In function 'compute_md5':
main.c:18:5: warning: 'MD5_Init' is deprecated: Since OpenSSL 3.0 [-Wdeprecated-declarations]
18 | MD5_Init(&md5ctx);
| ^~~~~~~~
In file included from main.c:4:
/usr/include/openssl/md5.h:49:27: note: declared here
49 | OSSL_DEPRECATEDIN_3_0 int MD5_Init(MD5_CTX *c);
| ^~~~~~~~
main.c:19:5: warning: 'MD5_Update' is deprecated: Since OpenSSL 3.0 [-Wdeprecated-declarations]
19 | MD5_Update(&md5ctx, str, strlen(str));
| ^~~~~~~~~~
/usr/include/openssl/md5.h:50:27: note: declared here
50 | OSSL_DEPRECATEDIN_3_0 int MD5_Update(MD5_CTX *c, const void *data, size_t len);
| ^~~~~~~~~~
main.c:20:5: warning: 'MD5_Final' is deprecated: Since OpenSSL 3.0 [-Wdeprecated-declarations]
20 | MD5_Final(result, &md5ctx);
| ^~~~~~~~~
/usr/include/openssl/md5.h:51:27: note: declared here
51 | OSSL_DEPRECATEDIN_3_0 int MD5_Final(unsigned char *md, MD5_CTX *c);
| ^~~~~~~~~
Testing if the previous output contains the string wrong
: True
Running the following program:
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 | #include <stdio.h> #include <string.h> #include <openssl/md5.h> unsigned char memory[1<<20]; void* malloc_ptr = (void*)&memory; void* my_malloc(int size) { void* ptr = malloc_ptr; malloc_ptr += size; return (void*)ptr; } void compute_md5(char *str, unsigned char *hex_result) { unsigned char result[MD5_DIGEST_LENGTH]; MD5_CTX md5ctx; MD5_Init(&md5ctx); MD5_Update(&md5ctx, str, strlen(str)); MD5_Final(result, &md5ctx); for (int i = 0; i < MD5_DIGEST_LENGTH; i++) { sprintf((char*)(hex_result + (i * 2)), "%02x", result[i]); } } int main(int argc, char** argv) { char* msg = (char*)my_malloc(32); char* result = (char*)my_malloc(33); msg[0] = ' '; compute_md5(argv[1], (unsigned char*)result); result[33] = ' '; strcat(msg, "Your password is wrong, "); strcat(msg, argv[2]); if (strcmp(result, "13bd041ac6e683f0c8ddba41eeed9e67") == 0) { puts("CORRECT!"); return 0; } else { puts(msg); return 1; } } |
CORRECT!
main.c: In function 'compute_md5':
main.c:18:5: warning: 'MD5_Init' is deprecated: Since OpenSSL 3.0 [-Wdeprecated-declarations]
18 | MD5_Init(&md5ctx);
| ^~~~~~~~
In file included from main.c:4:
/usr/include/openssl/md5.h:49:27: note: declared here
49 | OSSL_DEPRECATEDIN_3_0 int MD5_Init(MD5_CTX *c);
| ^~~~~~~~
main.c:19:5: warning: 'MD5_Update' is deprecated: Since OpenSSL 3.0 [-Wdeprecated-declarations]
19 | MD5_Update(&md5ctx, str, strlen(str));
| ^~~~~~~~~~
/usr/include/openssl/md5.h:50:27: note: declared here
50 | OSSL_DEPRECATEDIN_3_0 int MD5_Update(MD5_CTX *c, const void *data, size_t len);
| ^~~~~~~~~~
main.c:20:5: warning: 'MD5_Final' is deprecated: Since OpenSSL 3.0 [-Wdeprecated-declarations]
20 | MD5_Final(result, &md5ctx);
| ^~~~~~~~~
/usr/include/openssl/md5.h:51:27: note: declared here
51 | OSSL_DEPRECATEDIN_3_0 int MD5_Final(unsigned char *md, MD5_CTX *c);
| ^~~~~~~~~
Testing if the previous output contains the string CORRECT!
: True