local_1c = 0; local_10 = (void *)0x0; local_18 = (void *)0x0; do { puts( "========================================\n1) Create an user and choose an username\n2) Show user information\n3) Delete an user\n4) Write a note\n5) Show a note\n6) Save a note (not y et implemented)\n7) Delete a note\n8) Backup notes\n9) Quit\n=============================== =========\n\n" ); printf("Your choice: "); __isoc99_scanf(&DAT_0010212b,&local_1c); puts(""); switch(local_1c) { default: /* WARNING: Subroutine does not return */ exit(0); case1: // Create an user and choose an username // 申请内存 local_10 = malloc(0x28); if (local_10 == (void *)0x0) { /* WARNING: Subroutine does not return */ exit(-1); } memset(local_10,0,0x18); memset((void *)((long)local_10 + 0x18),0,0x10); _Var1 = getuid();
if (_Var1 == 0) { // uid为0则设置这块内存的内容为admin(小端存储) *(undefined4 *)((long)local_10 + 0x18) = 0x696d6461; *(undefined *)((long)local_10 + 0x1c) = 0x6e; } else { // 否则设置为user *(undefined4 *)((long)local_10 + 0x18) = 0x72657375; } printf("Choose an username: "); // 输入用户名再返回信息 __isoc99_scanf(&DAT_00102144,local_10); puts(""); break; case2: // Show user information if (local_10 == (void *)0x0) { puts("First create an user!\n"); } else { printf("\nUsername: %s\n",local_10); printf("Role: %s\n\n",(long)local_10 + 0x18); } break; case3: // Delete an user if (local_10 != (void *)0x0) { free(local_10); // 问题的关键,这里释放了内存,但并没有删除该指针 } break; case4: // Write a note local_18 = malloc(0x28); memset(local_18,0,0x28); if (local_18 == (void *)0x0) { /* WARNING: Subroutine does not return */ exit(-1); } puts("Write your note:"); __isoc99_scanf(&DAT_0010218b,local_18); break; case5: // Show a note printf("Note: %s\n\n",local_18); break; case6: // Save a note (not yet implemented) puts("Coming soon!\n"); break; case7: // Delete a note if (local_18 != (void *)0x0) { free(local_18); local_18 = (void *)0x0; } break; case8: // Backup notes if (local_10 == (void *)0x0) { puts("First create an user!\n"); } else { iVar2 = strcmp((char *)((long)local_10 + 0x18),"admin"); if (iVar2 == 0) { puts("Access granted!"); // 使用root权限执行以下tar命令 setuid(0); setgid(0); system("tar -czvf /root/backups/backup_notes.tar.gz /opt/notes"); } else { puts("Access denied: you don\'t have the admin role!\n"); } } } } while( true ); }