IITGN-CS431 / project-cns

1 stars 27 forks source link

[Security BUG] Bug in validating username Group 1 #262

Closed RuchitJagodara closed 1 week ago

RuchitJagodara commented 1 week ago

Here your valid_username function is vulnerable to bit exploitation attack and below is the procedure that I used to do the attack I think you can also recreate it using the same.

Here, as you can see I gave empty input in the username but still it worked and My registration was successful !

ruchitjagodara@ruchitjagodara:~/Education/CNS/project-cns/project-submissions/group-1/build$ gdb atm
GNU gdb (Ubuntu 15.0.50.20240403-0ubuntu1) 15.0.50.20240403-git
Copyright (C) 2024 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from atm...
(gdb) break validate_username
Breakpoint 1 at 0x765d: file atm_final.cpp, line 90.
(gdb) run
Starting program: /home/ruchitjagodara/Education/CNS/project-cns/project-submissions/group-1/build/requirements/atm 

This GDB supports auto-downloading debuginfo from the following URLs:
  <https://debuginfod.ubuntu.com>
Enable debuginfod for this session? (y or [n]) y
Debuginfod has been enabled.
To make this setting permanent, add 'set debuginfod enabled on' to .gdbinit.
Downloading separate debug info for system-supplied DSO at 0x7ffff7fc3000
Downloading separate debug info for /lib/x86_64-linux-gnu/libssl.so.3                                                                                                
Downloading separate debug info for /lib/x86_64-linux-gnu/libcrypto.so.3                                                                                             
Downloading separate debug info for /lib/x86_64-linux-gnu/libstdc++.so.6                                                                                             
Downloading separate debug info for /lib/x86_64-linux-gnu/libgcc_s.so.1                                                                                              
[Thread debugging using libthread_db enabled]                                                                                                                        
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Server: VERIFIED
ATM Menu:
1. Register
2. Login
3. Exit
Enter your choice: 1

Breakpoint 1, validate_username (username="") at atm_final.cpp:90
90  {
(gdb) continue 
Continuing.
Enter username (allowed: [_-., digits, lowercase letters], 1-122 chars): 

Breakpoint 1, validate_username (username="") at atm_final.cpp:90
90  {
(gdb) disassemble validate_username
Dump of assembler code for function _Z17validate_usernameRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE:
   0x000055555555b64c <+0>: endbr64
   0x000055555555b650 <+4>: push   %rbp
   0x000055555555b651 <+5>: mov    %rsp,%rbp
   0x000055555555b654 <+8>: push   %rbx
   0x000055555555b655 <+9>: sub    $0x48,%rsp
   0x000055555555b659 <+13>:    mov    %rdi,-0x48(%rbp)
=> 0x000055555555b65d <+17>:    mov    %fs:0x28,%rax
   0x000055555555b666 <+26>:    mov    %rax,-0x18(%rbp)
   0x000055555555b66a <+30>:    xor    %eax,%eax
   0x000055555555b66c <+32>:    mov    -0x48(%rbp),%rax
   0x000055555555b670 <+36>:    mov    %rax,%rdi
   0x000055555555b673 <+39>:    call   0x55555555acb0 <_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE6lengthEv@plt>
   0x000055555555b678 <+44>:    test   %rax,%rax
   0x000055555555b67b <+47>:    je     0x55555555b68f <_Z17validate_usernameRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE+67>
   0x000055555555b67d <+49>:    mov    -0x48(%rbp),%rax
   0x000055555555b681 <+53>:    mov    %rax,%rdi
   0x000055555555b684 <+56>:    call   0x55555555acb0 <_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE6lengthEv@plt>
   0x000055555555b689 <+61>:    cmp    $0x7a,%rax
   0x000055555555b68d <+65>:    jbe    0x55555555b696 <_Z17validate_usernameRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE+74>
   0x000055555555b68f <+67>:    mov    $0x1,%eax
   0x000055555555b694 <+72>:    jmp    0x55555555b69b <_Z17validate_usernameRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE+79>
   0x000055555555b696 <+74>:    mov    $0x0,%eax
   0x000055555555b69b <+79>:    test   %al,%al
   0x000055555555b69d <+81>:    je     0x55555555b6a6 <_Z17validate_usernameRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE+90>
   0x000055555555b69f <+83>:    mov    $0x0,%ebx
   0x000055555555b6a4 <+88>:    jmp    0x55555555b6f5 <_Z17validate_usernameRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE+169>
   0x000055555555b6a6 <+90>:    lea    -0x40(%rbp),%rax
   0x000055555555b6aa <+94>:    mov    $0x10,%edx
   0x000055555555b6af <+99>:    lea    0x32a9c(%rip),%rcx        # 0x55555558e152
   0x000055555555b6b6 <+106>:   mov    %rcx,%rsi
   0x000055555555b6b9 <+109>:   mov    %rax,%rdi
   0x000055555555b6bc <+112>:   call   0x55555555f666 <_ZNSt7__cxx1111basic_regexIcNS_12regex_traitsIcEEEC2EPKcNSt15regex_constants18syntax_option_typeE>
   0x000055555555b6c1 <+117>:   lea    -0x40(%rbp),%rcx
   0x000055555555b6c5 <+121>:   mov    -0x48(%rbp),%rax
   0x000055555555b6c9 <+125>:   mov    $0x0,%edx
   0x000055555555b6ce <+130>:   mov    %rcx,%rsi
   0x000055555555b6d1 <+133>:   mov    %rax,%rdi
   0x000055555555b6d4 <+136>:   call   0x55555555f737 <_ZSt11regex_matchISt11char_traitsIcESaIcEcNSt7__cxx1112regex_traitsIcEEEbRKNS3_12basic_stringIT1_T_T0_EERKNS3_11basic_regexIS7_T2_EENSt15regex_constants15match_flag_typeE>
--Type <RET> for more, q to quit, c to continue without paging--
   0x000055555555b6d9 <+141>:   test   %al,%al
   0x000055555555b6db <+143>:   je     0x55555555b6e4 <_Z17validate_usernameRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE+152>
   0x000055555555b6dd <+145>:   mov    $0x1,%ebx
   0x000055555555b6e2 <+150>:   jmp    0x55555555b6e9 <_Z17validate_usernameRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE+157>
   0x000055555555b6e4 <+152>:   mov    $0x0,%ebx
   0x000055555555b6e9 <+157>:   lea    -0x40(%rbp),%rax
   0x000055555555b6ed <+161>:   mov    %rax,%rdi
   0x000055555555b6f0 <+164>:   call   0x55555555f704 <_ZNSt7__cxx1111basic_regexIcNS_12regex_traitsIcEEED2Ev>
   0x000055555555b6f5 <+169>:   mov    %ebx,%eax
   0x000055555555b6f7 <+171>:   mov    -0x18(%rbp),%rdx
   0x000055555555b6fb <+175>:   sub    %fs:0x28,%rdx
   0x000055555555b704 <+184>:   je     0x55555555b73f <_Z17validate_usernameRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE+243>
   0x000055555555b706 <+186>:   jmp    0x55555555b73a <_Z17validate_usernameRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE+238>
   0x000055555555b708 <+188>:   endbr64
   0x000055555555b70c <+192>:   mov    %rax,%rbx
   0x000055555555b70f <+195>:   lea    -0x40(%rbp),%rax
   0x000055555555b713 <+199>:   mov    %rax,%rdi
   0x000055555555b716 <+202>:   call   0x55555555f704 <_ZNSt7__cxx1111basic_regexIcNS_12regex_traitsIcEEED2Ev>
   0x000055555555b71b <+207>:   mov    %rbx,%rax
   0x000055555555b71e <+210>:   mov    -0x18(%rbp),%rdx
   0x000055555555b722 <+214>:   sub    %fs:0x28,%rdx
   0x000055555555b72b <+223>:   je     0x55555555b732 <_Z17validate_usernameRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE+230>
   0x000055555555b72d <+225>:   call   0x55555555aa50 <__stack_chk_fail@plt>
   0x000055555555b732 <+230>:   mov    %rax,%rdi
   0x000055555555b735 <+233>:   call   0x55555555ad50 <_Unwind_Resume@plt>
   0x000055555555b73a <+238>:   call   0x55555555aa50 <__stack_chk_fail@plt>
   0x000055555555b73f <+243>:   mov    -0x8(%rbp),%rbx
   0x000055555555b743 <+247>:   leave
   0x000055555555b744 <+248>:   ret
End of assembler dump.
(gdb) stepi
0x000055555555b666  90  {
(gdb) stepi
0x000055555555b66a  90  {
(gdb) stepi
92      if (username.length() < 1 || username.length() > 122)
(gdb) stepi
0x000055555555b670  92      if (username.length() < 1 || username.length() > 122)
(gdb) stepi
0x000055555555b673  92      if (username.length() < 1 || username.length() > 122)
(gdb) i r
rax            0x7fffffffc020      140737488338976
rbx            0x20                32
rcx            0x7ffff711ba61      140737338522209
rdx            0x0                 0
rsi            0x20                32
rdi            0x7fffffffc020      140737488338976
rbp            0x7fffffffbf00      0x7fffffffbf00
rsp            0x7fffffffbeb0      0x7fffffffbeb0
r8             0x7ffff71b28c0      140737339140288
r9             0x0                 0
r10            0x7ffff7414190      140737341637008
r11            0x246               582
r12            0x1                 1
r13            0x0                 0
r14            0x5555555a45d8      93824992560600
r15            0x7ffff7ffd000      140737354125312
rip            0x55555555b673      0x55555555b673 <validate_username(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)+39>
eflags         0x246               [ PF ZF IF ]
cs             0x33                51
ss             0x2b                43
ds             0x0                 0
es             0x0                 0
fs             0x0                 0
gs             0x0                 0
fs_base        0x7ffff7ddcb80      140737351895936
gs_base        0x0                 0
(gdb) stepi
0x000055555555acb0 in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::length() const@plt ()
(gdb) stepi
0x000055555555acb4 in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::length() const@plt ()
(gdb) stepi
Downloading source file /build/gcc-14-ig5ci0/gcc-14-14.2.0/build/x86_64-linux-gnu/libstdc++-v3/include/bits/basic_string.h
std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::length (this=0x7fffffffc020)                                                        
    at /build/gcc-14-ig5ci0/gcc-14-14.2.0/build/x86_64-linux-gnu/libstdc++-v3/include/bits/basic_string.h:1083
warning: 1083   /build/gcc-14-ig5ci0/gcc-14-14.2.0/build/x86_64-linux-gnu/libstdc++-v3/include/bits/basic_string.h: No such file or directory
(gdb) stepi
0x00007ffff7568d24  1084    in /build/gcc-14-ig5ci0/gcc-14-14.2.0/build/x86_64-linux-gnu/libstdc++-v3/include/bits/basic_string.h
(gdb) stepi
0x00007ffff7568d28  1084    in /build/gcc-14-ig5ci0/gcc-14-14.2.0/build/x86_64-linux-gnu/libstdc++-v3/include/bits/basic_string.h
(gdb) stepi
0x000055555555b678 in validate_username (username="") at atm_final.cpp:92
92      if (username.length() < 1 || username.length() > 122)
(gdb) stepi
0x000055555555b67b  92      if (username.length() < 1 || username.length() > 122)
(gdb) stepi
0x000055555555b68f  92      if (username.length() < 1 || username.length() > 122)
(gdb) stepi
0x000055555555b694  92      if (username.length() < 1 || username.length() > 122)
(gdb) stepi
0x000055555555b69b  92      if (username.length() < 1 || username.length() > 122)
(gdb) stepi
0x000055555555b69d  92      if (username.length() < 1 || username.length() > 122)
(gdb) stepi
94          return false;
(gdb) i r
rax            0x1                 1
rbx            0x20                32
rcx            0x7ffff711ba61      140737338522209
rdx            0x0                 0
rsi            0x20                32
rdi            0x7fffffffc020      140737488338976
rbp            0x7fffffffbf00      0x7fffffffbf00
rsp            0x7fffffffbeb0      0x7fffffffbeb0
r8             0x7ffff71b28c0      140737339140288
r9             0x0                 0
r10            0x7ffff7414190      140737341637008
r11            0x246               582
r12            0x1                 1
r13            0x0                 0
r14            0x5555555a45d8      93824992560600
r15            0x7ffff7ffd000      140737354125312
rip            0x55555555b69f      0x55555555b69f <validate_username(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)+83>
eflags         0x202               [ IF ]
cs             0x33                51
ss             0x2b                43
ds             0x0                 0
es             0x0                 0
fs             0x0                 0
gs             0x0                 0
fs_base        0x7ffff7ddcb80      140737351895936
gs_base        0x0                 0
(gdb) stepi
0x000055555555b6a4  94          return false;
(gdb) i r
rax            0x1                 1
rbx            0x0                 0
rcx            0x7ffff711ba61      140737338522209
rdx            0x0                 0
rsi            0x20                32
rdi            0x7fffffffc020      140737488338976
rbp            0x7fffffffbf00      0x7fffffffbf00
rsp            0x7fffffffbeb0      0x7fffffffbeb0
r8             0x7ffff71b28c0      140737339140288
r9             0x0                 0
r10            0x7ffff7414190      140737341637008
r11            0x246               582
r12            0x1                 1
r13            0x0                 0
r14            0x5555555a45d8      93824992560600
r15            0x7ffff7ffd000      140737354125312
rip            0x55555555b6a4      0x55555555b6a4 <validate_username(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)+88>
eflags         0x202               [ IF ]
cs             0x33                51
ss             0x2b                43
ds             0x0                 0
es             0x0                 0
fs             0x0                 0
gs             0x0                 0
fs_base        0x7ffff7ddcb80      140737351895936
gs_base        0x0                 0
(gdb) stepi
0x000055555555b6f5  105 }
(gdb) i r
rax            0x1                 1
rbx            0x0                 0
rcx            0x7ffff711ba61      140737338522209
rdx            0x0                 0
rsi            0x20                32
rdi            0x7fffffffc020      140737488338976
rbp            0x7fffffffbf00      0x7fffffffbf00
rsp            0x7fffffffbeb0      0x7fffffffbeb0
r8             0x7ffff71b28c0      140737339140288
r9             0x0                 0
r10            0x7ffff7414190      140737341637008
r11            0x246               582
r12            0x1                 1
r13            0x0                 0
r14            0x5555555a45d8      93824992560600
r15            0x7ffff7ffd000      140737354125312
rip            0x55555555b6f5      0x55555555b6f5 <validate_username(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)+169>
eflags         0x202               [ IF ]
cs             0x33                51
ss             0x2b                43
ds             0x0                 0
es             0x0                 0
fs             0x0                 0
gs             0x0                 0
fs_base        0x7ffff7ddcb80      140737351895936
gs_base        0x0                 0
(gdb) stepi
0x000055555555b6f7  105 }
(gdb) stepi
0x000055555555b6fb  105 }
(gdb) stepi
0x000055555555b704  105 }
(gdb) stepi
0x000055555555b73f  105 }
(gdb) i r
rax            0x0                 0
rbx            0x0                 0
rcx            0x7ffff711ba61      140737338522209
rdx            0x0                 0
rsi            0x20                32
rdi            0x7fffffffc020      140737488338976
rbp            0x7fffffffbf00      0x7fffffffbf00
rsp            0x7fffffffbeb0      0x7fffffffbeb0
r8             0x7ffff71b28c0      140737339140288
r9             0x0                 0
r10            0x7ffff7414190      140737341637008
r11            0x246               582
r12            0x1                 1
r13            0x0                 0
r14            0x5555555a45d8      93824992560600
r15            0x7ffff7ffd000      140737354125312
rip            0x55555555b73f      0x55555555b73f <validate_username(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)+243>
eflags         0x246               [ PF ZF IF ]
cs             0x33                51
ss             0x2b                43
ds             0x0                 0
es             0x0                 0
fs             0x0                 0
gs             0x0                 0
fs_base        0x7ffff7ddcb80      140737351895936
gs_base        0x0                 0
(gdb) set $rax=0x1
(gdb) i r
rax            0x1                 1
rbx            0x0                 0
rcx            0x7ffff711ba61      140737338522209
rdx            0x0                 0
rsi            0x20                32
rdi            0x7fffffffc020      140737488338976
rbp            0x7fffffffbf00      0x7fffffffbf00
rsp            0x7fffffffbeb0      0x7fffffffbeb0
r8             0x7ffff71b28c0      140737339140288
r9             0x0                 0
r10            0x7ffff7414190      140737341637008
r11            0x246               582
r12            0x1                 1
r13            0x0                 0
r14            0x5555555a45d8      93824992560600
r15            0x7ffff7ffd000      140737354125312
rip            0x55555555b73f      0x55555555b73f <validate_username(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)+243>
eflags         0x246               [ PF ZF IF ]
cs             0x33                51
ss             0x2b                43
ds             0x0                 0
es             0x0                 0
fs             0x0                 0
gs             0x0                 0
fs_base        0x7ffff7ddcb80      140737351895936
gs_base        0x0                 0
(gdb) stepi
0x000055555555b743  105 }
(gdb) stepi
0x000055555555b744  105 }
(gdb) stepi
0x000055555555c13f in main () at atm_final.cpp:327
327                     if(!has_spaces(username) && validate_username(username)){
(gdb) stepi
0x000055555555c141  327                     if(!has_spaces(username) && validate_username(username)){
(gdb) stepi
0x000055555555c143  327                     if(!has_spaces(username) && validate_username(username)){
(gdb) stepi
0x000055555555c148  327                     if(!has_spaces(username) && validate_username(username)){
(gdb) stepi
0x000055555555c14f  327                     if(!has_spaces(username) && validate_username(username)){
(gdb) stepi
0x000055555555c151  327                     if(!has_spaces(username) && validate_username(username)){
(gdb) stepi
328                         break;
(gdb) stepi
333                 bool valid_password = false;
(gdb) continue
Continuing.
Enter password (min 8 chars, must include uppercase, lowercase, number, special char, no spaces): hellow_username worked bit exploitation successful
Password too weak or contains spaces! Please try again.
Enter password (min 8 chars, must include uppercase, lowercase, number, special char, no spaces): YeahItworked!@#303WOW
Enter initial deposit amount (must be formatted as 0.00): 10.00
Server: Registration successful!
ATM Menu:
1. Register
2. Login
3. Exit
Enter your choice: 

Here, as you can see I gave empty input in the username but still it worked and My registration was successful !

bichhawat commented 1 week ago

Can you check if you can login again using the empty username and the password you provided during registration and post the output, too? Changing the register values using GDB, while appreciated, does not constitute a bug as I can modify any values at any time. The same needs to work once you are out of that and trying to reaccess the system.

RuchitJagodara commented 1 week ago

Continuing. Enter password (min 8 chars, must include uppercase, lowercase, number, special char, no spaces): hellow_username worked bit exploitation successful Password too weak or contains spaces! Please try again. Enter password (min 8 chars, must include uppercase, lowercase, number, special char, no spaces): YeahItworked!@#303WOW Enter initial deposit amount (must be formatted as 0.00): 10.00 Server: Registration successful!

But sir, here as you can see I am getting a registration successful message right, which means I was able to register myself with that username on the server also, but according to the specs I should not be able to register using this name....

bichhawat commented 1 week ago

Ok, I am clubbing this with the password one, as they are the same functionality issues.

RuchitJagodara commented 1 week ago

@bichhawat below is my updated log as you can see after the attack I was able to deposit amount also with the invalid username

ruchitjagodara@ruchitjagodara:~/Education/CNS/project-cns/project-submissions/group-1/build$ gdb atm
GNU gdb (Ubuntu 15.0.50.20240403-0ubuntu1) 15.0.50.20240403-git
Copyright (C) 2024 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from atm...
(gdb) break validate_username
Breakpoint 1 at 0x765d: file atm_final.cpp, line 90.
(gdb) run
Starting program: /home/ruchitjagodara/Education/CNS/project-cns/project-submissions/group-1/build/requirements/atm 

This GDB supports auto-downloading debuginfo from the following URLs:
  <https://debuginfod.ubuntu.com>
Enable debuginfod for this session? (y or [n]) y
Debuginfod has been enabled.
To make this setting permanent, add 'set debuginfod enabled on' to .gdbinit.
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Server: VERIFIED
ATM Menu:
1. Register
2. Login
3. Exit
Enter your choice: 1

Breakpoint 1, validate_username (username="") at atm_final.cpp:90
90  {
(gdb) continue
Continuing.
Enter username (allowed: [_-., digits, lowercase letters], 1-122 chars): @@@@@UnvalidUsername

Breakpoint 1, validate_username (username="@@@@@UnvalidUsername") at atm_final.cpp:90
90  {
(gdb) disassemble validate_username
Dump of assembler code for function _Z17validate_usernameRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE:
   0x000055555555b64c <+0>: endbr64
   0x000055555555b650 <+4>: push   %rbp
   0x000055555555b651 <+5>: mov    %rsp,%rbp
   0x000055555555b654 <+8>: push   %rbx
   0x000055555555b655 <+9>: sub    $0x48,%rsp
   0x000055555555b659 <+13>:    mov    %rdi,-0x48(%rbp)
=> 0x000055555555b65d <+17>:    mov    %fs:0x28,%rax
   0x000055555555b666 <+26>:    mov    %rax,-0x18(%rbp)
   0x000055555555b66a <+30>:    xor    %eax,%eax
   0x000055555555b66c <+32>:    mov    -0x48(%rbp),%rax
   0x000055555555b670 <+36>:    mov    %rax,%rdi
   0x000055555555b673 <+39>:    call   0x55555555acb0 <_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE6lengthEv@plt>
   0x000055555555b678 <+44>:    test   %rax,%rax
   0x000055555555b67b <+47>:    je     0x55555555b68f <_Z17validate_usernameRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE+67>
   0x000055555555b67d <+49>:    mov    -0x48(%rbp),%rax
   0x000055555555b681 <+53>:    mov    %rax,%rdi
   0x000055555555b684 <+56>:    call   0x55555555acb0 <_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE6lengthEv@plt>
   0x000055555555b689 <+61>:    cmp    $0x7a,%rax
   0x000055555555b68d <+65>:    jbe    0x55555555b696 <_Z17validate_usernameRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE+74>
   0x000055555555b68f <+67>:    mov    $0x1,%eax
   0x000055555555b694 <+72>:    jmp    0x55555555b69b <_Z17validate_usernameRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE+79>
   0x000055555555b696 <+74>:    mov    $0x0,%eax
   0x000055555555b69b <+79>:    test   %al,%al
   0x000055555555b69d <+81>:    je     0x55555555b6a6 <_Z17validate_usernameRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE+90>
   0x000055555555b69f <+83>:    mov    $0x0,%ebx
   0x000055555555b6a4 <+88>:    jmp    0x55555555b6f5 <_Z17validate_usernameRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE+169>
   0x000055555555b6a6 <+90>:    lea    -0x40(%rbp),%rax
   0x000055555555b6aa <+94>:    mov    $0x10,%edx
   0x000055555555b6af <+99>:    lea    0x32a9c(%rip),%rcx        # 0x55555558e152
   0x000055555555b6b6 <+106>:   mov    %rcx,%rsi
   0x000055555555b6b9 <+109>:   mov    %rax,%rdi
   0x000055555555b6bc <+112>:   call   0x55555555f666 <_ZNSt7__cxx1111basic_regexIcNS_12regex_traitsIcEEEC2EPKcNSt15regex_constants18syntax_option_typeE>
   0x000055555555b6c1 <+117>:   lea    -0x40(%rbp),%rcx
   0x000055555555b6c5 <+121>:   mov    -0x48(%rbp),%rax
   0x000055555555b6c9 <+125>:   mov    $0x0,%edx
   0x000055555555b6ce <+130>:   mov    %rcx,%rsi
   0x000055555555b6d1 <+133>:   mov    %rax,%rdi
   0x000055555555b6d4 <+136>:   call   0x55555555f737 <_ZSt11regex_matchISt11char_traitsIcESaIcEcNSt7__cxx1112regex_traitsIcEEEbRKNS3_12basic_stringIT1_T_T0_EERKNS3_11basic_regexIS7_T2_EENSt15regex_constants15match_flag_typeE>
--Type <RET> for more, q to quit, c to continue without paging--
   0x000055555555b6d9 <+141>:   test   %al,%al
   0x000055555555b6db <+143>:   je     0x55555555b6e4 <_Z17validate_usernameRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE+152>
   0x000055555555b6dd <+145>:   mov    $0x1,%ebx
   0x000055555555b6e2 <+150>:   jmp    0x55555555b6e9 <_Z17validate_usernameRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE+157>
   0x000055555555b6e4 <+152>:   mov    $0x0,%ebx
   0x000055555555b6e9 <+157>:   lea    -0x40(%rbp),%rax
   0x000055555555b6ed <+161>:   mov    %rax,%rdi
   0x000055555555b6f0 <+164>:   call   0x55555555f704 <_ZNSt7__cxx1111basic_regexIcNS_12regex_traitsIcEEED2Ev>
   0x000055555555b6f5 <+169>:   mov    %ebx,%eax
   0x000055555555b6f7 <+171>:   mov    -0x18(%rbp),%rdx
   0x000055555555b6fb <+175>:   sub    %fs:0x28,%rdx
   0x000055555555b704 <+184>:   je     0x55555555b73f <_Z17validate_usernameRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE+243>
   0x000055555555b706 <+186>:   jmp    0x55555555b73a <_Z17validate_usernameRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE+238>
   0x000055555555b708 <+188>:   endbr64
   0x000055555555b70c <+192>:   mov    %rax,%rbx
   0x000055555555b70f <+195>:   lea    -0x40(%rbp),%rax
   0x000055555555b713 <+199>:   mov    %rax,%rdi
   0x000055555555b716 <+202>:   call   0x55555555f704 <_ZNSt7__cxx1111basic_regexIcNS_12regex_traitsIcEEED2Ev>
   0x000055555555b71b <+207>:   mov    %rbx,%rax
   0x000055555555b71e <+210>:   mov    -0x18(%rbp),%rdx
   0x000055555555b722 <+214>:   sub    %fs:0x28,%rdx
   0x000055555555b72b <+223>:   je     0x55555555b732 <_Z17validate_usernameRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE+230>
   0x000055555555b72d <+225>:   call   0x55555555aa50 <__stack_chk_fail@plt>
   0x000055555555b732 <+230>:   mov    %rax,%rdi
   0x000055555555b735 <+233>:   call   0x55555555ad50 <_Unwind_Resume@plt>
   0x000055555555b73a <+238>:   call   0x55555555aa50 <__stack_chk_fail@plt>
   0x000055555555b73f <+243>:   mov    -0x8(%rbp),%rbx
   0x000055555555b743 <+247>:   leave
   0x000055555555b744 <+248>:   ret
End of assembler dump.
(gdb) break *0x000055555555b744
Breakpoint 2 at 0x55555555b744: file atm_final.cpp, line 105.
(gdb) continue
Continuing.

Breakpoint 2, 0x000055555555b744 in validate_username (username="@@@@@UnvalidUsername") at atm_final.cpp:105
105 }
(gdb) set $rax=0x1
(gdb) continue
Continuing.
Enter password (min 8 chars, must include uppercase, lowercase, number, special char, no spaces): YeahItworked!@#303WOW 
Enter initial deposit amount (must be formatted as 0.00): 10.00
Server: Registration successful!
ATM Menu:
1. Register
2. Login
3. Exit
Enter your choice: 2
Enter username (allowed: [_-., digits, lowercase letters], 1-122 chars): @@@@@UnvalidUsername

Breakpoint 1, validate_username (username="@@@@@UnvalidUsername") at atm_final.cpp:90
90  {
(gdb) continue
Continuing.

Breakpoint 2, 0x000055555555b744 in validate_username (username="@@@@@UnvalidUsername") at atm_final.cpp:105
105 }
(gdb) set $rax=0x1
(gdb) continue
Continuing.

Breakpoint 1, validate_username (username="@@@@@UnvalidUsername") at atm_final.cpp:90
90  {
(gdb) continue
Continuing.

Breakpoint 2, 0x000055555555b744 in validate_username (username="@@@@@UnvalidUsername") at atm_final.cpp:105
105 }
(gdb) set $rax=0x1
(gdb) continue
Continuing.
Enter password: YeahItworked!@#303WOW 
Server: Login successful! SessionID: YUTZJIGSNGLQSDIH

Logged in. What would you like to do?
1. Check Balance
2. Deposit Money
3. Withdraw Money
4. View past transactions
5. Logout
Enter your choice: 2
Enter amount to deposit: 2
255- Invalid amount! Please enter a valid amount in the format: whole.fractional (e.g., 123.45) and within bounds (0.00, 4294967295.99].

Logged in. What would you like to do?
1. Check Balance
2. Deposit Money
3. Withdraw Money
4. View past transactions
5. Logout
Enter your choice: 2
Enter amount to deposit: 2.00
Server: Deposited $2.00. New balance: $12.00

Logged in. What would you like to do?
1. Check Balance
2. Deposit Money
3. Withdraw Money
4. View past transactions
5. Logout
Enter your choice: 
RuchitJagodara commented 1 week ago

@bichhawat, can you please mark this as a security bug, as they have a functionality check for validation of username but I bypassed it right, so shouldn't this be a security bug ?

And same for #265

Pratham-Sharda commented 1 week ago

@bichhawat Sir again the changing of values of register generated by code and not during transmission or connection should be considered as changing of code (implicitly) and thus should we still consider it as a bug as given if i can change the register values generated by code i can run the program with any desired output i want .

bichhawat commented 1 week ago

@Pratham-Sharda This is still on the client side, if I understand correctly, which breaks the functionality requirements. There are checks that can defeat this kind of attack, which need to be enforced.

@RuchitJagodara The reason that this is not a security bug is that the functionality for checking usernames is not correctly enforced. This requires simple checks, which could have addressed the issue. Moreover, this does not allow a rogue user to modify the database without the right credentials. Similarly, if you could access/modify someone else's data, that would be a security bug