0

gdb-pedaでファイル(chall)を実行すると、入力画面で停止せず終了してしまいます。

$ gdb chall
GNU gdb (Debian 13.2-1) 13.2
Copyright (C) 2023 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 chall...
(No debugging symbols found in chall)
gdb-peda$ r
Starting program: /home/myusername/Desktop/seccon2023/pwnable/rop-2.35/chall 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[Attaching after Thread 0x7ffff7dc7740 (LWP 21993) vfork to child process 21996]
[New inferior 2 (process 21996)]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[Detaching vfork parent process 21993 after child exec]
[Inferior 1 (process 21993) detached]
process 21996 is executing new program: /usr/bin/dash
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Enter something:
[Inferior 2 (process 21996) exited normally]
Warning: 'set logging off', an alias for the command 'set logging enabled', is deprecated.
Use 'set logging enabled off'.

Warning: 'set logging on', an alias for the command 'set logging enabled', is deprecated.
Use 'set logging enabled on'.

Warning: not running

一応下から9行目で「Enter something:」のように表示されています。本来ならばここで停止し、何か入力しエンターを押すまで停止するのが正常動作のはずです。

一方、gdbinitから

source ~/peda/peda.py

を削除し、gdbで実行した場合は「Enter something:」が表示され、入力を待ち受けます。

└─$ gdb chall     
GNU gdb (Debian 13.2-1) 13.2
Copyright (C) 2023 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 chall...
(No debugging symbols found in chall)
(gdb) r
Starting program: /home/myusername/Desktop/seccon2023/pwnable/rop-2.35/chall 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[Detaching after vfork from child process 23254]
Enter something:

どこに着目してエラー解決に臨めばいいでしょうか。どなたか知見のある方お願いいたします。

1 件の回答 1

0

set follow-fork-mode parent を実行してから run してみてはいかがでしょう。

gdb-peda では follow-fork-mode がデフォルトで child に設定されています [1]。

質問者様が利用されているバイナリはこちら [2] のものかと伺っております。
system("echo Enter something:"); が呼ばれて、fork で子プロセスを生成します。
この際、gdb の設定で follow-fork-modechild と設定されておりますと、子プロセスが終了した際にデバッグも終了します。

手元の環境 (GNU gdb (Debian 13.2-1) 13.2, gdb-peda v1.2) で検証したところ、set follow-fork-mode parent を実行することで期待通りに Enter something: で入力を待ってくれるようになりました。

$ gdb -q ./chall
Reading symbols from ./chall...
(No debugging symbols found in ./chall)
gdb-peda$ show follow-fork-mode
Debugger response to a program call of fork or vfork is "child".
gdb-peda$ set follow-fork-mode parent
gdb-peda$ r
Starting program: /root/Downloads/SECCON2023_online_CTF/pwnable/rop-2.35/files/rop-2.35/chall
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[Detaching after vfork from child process 40895]
Enter something:
test
[Inferior 1 (process 40882) exited with code 0260]
Warning: not running

ちなみに、こちらの GitHub Issue [3] でも同様の話題が上がっておりますね。

[1] https://github.com/longld/peda/blob/f76c34d5e0c1f8e5603d5f03a794d096507c402e/peda.py#L6159
[2] https://github.com/SECCON/SECCON2023_online_CTF/blob/main/pwnable/rop-2.35/files/rop-2.35/chall
[3] https://github.com/longld/peda/issues/143

この質問に回答するには、ログインする必要があります。

求めていた回答ではありませんか? のタグが付いた他の質問を参照する。