Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore a warning when compiling with asm #2508

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

sbancuz
Copy link

@sbancuz sbancuz commented Dec 23, 2024

Pwntools Pull Request

This pr ingores the '-Wunused-command-line-argument' warning from the cpp builtin. Since any warning in asm.py makes the process errror out, it makes using something like asm(shellcraft.sh()) when on nix impossible. See log below

✦ ❯ cat log.txt                                                                                                                                                                                                                             
================================================================================                                                                                                                                                            
= Started at 2024-12-23T23:37:31                                               =                                                                                                                                                            
= sys.argv = [                                                                 =                                                                                                                                                            
=   'back_to_shell_sol.py',                                                    =                                                                                                                                                            
= ]                                                                            =                                                                                                                                                            
================================================================================                                                                                                                                                            
================================================================================                                                                                                                                                            
= Started at 2024-12-23T23:37:31                                               =                                                                                                                                                            
= sys.argv = [                                                                 =                                                                                                                                                            
=   'back_to_shell_sol.py',                                                    =                                                                                                                                                            
= ]                                                                            =                                                                                                                                                            
================================================================================                                                                                                                                                            
2024-12-23T23:37:31:INFO:pwnlib.tubes.process.process.140272202976464:Starting local process './back_to_shell' argv=[b'./back_to_shell']                                                                                                    
2024-12-23T23:37:31:INFO:pwnlib.tubes.process.process.140272202976464:Starting local process './back_to_shell' argv=[b'./back_to_shell'] : pid 181737                                                                                       
2024-12-23T23:37:31:DEBUG:pwnlib.tubes.process.process.140272202976464:Received 0xb bytes:                                                                                                                                                  
2024-12-23T23:37:31:DEBUG:pwnlib.tubes.process.process.140272202976464:b'Shellcode: '                                                                                                                                                       
2024-12-23T23:37:32:DEBUG:pwnlib.asm:cpp -C -nostdinc -undef -P -I/nix/store/lbajkkyhz123azc3d5yp0bbhz7bin6gr-python3.11-pwntools-4.12.0/lib/python3.11/site-packages/pwnlib/data/includes /dev/stdin                                       
2024-12-23T23:37:32:ERROR:pwnlib.asm:There was an error running ['cpp', '-C', '-nostdinc', '-undef', '-P', '-I/nix/store/lbajkkyhz123azc3d5yp0bbhz7bin6gr-python3.11-pwntools-4.12.0/lib/python3.11/site-packages/pwnlib/data/includes', '/d
ev/stdin']:                                                                                                                                                                                                                                 
It had this on stdout:                                                                                                                                                                                                                      
cpp: warning: -Wl,-dynamic-linker=/nix/store/wn7v2vhyyyi6clcyn0s9ixvl7d4d87ic-glibc-2.40-36/lib/ld-linux-x86-64.so.2: 'linker' input unused in cpp mode [-Wunused-command-line-argument]                                                    
cpp: warning: -Wl,-rpath: 'linker' input unused in cpp mode [-Wunused-command-line-argument]                                                                                                                                                
cpp: warning: -Wl,/var/home/sbancuz/dev/odc/outputs/out/lib: 'linker' input unused in cpp mode [-Wunused-command-line-argument]                                                                                                             
cpp: warning: argument unused during compilation: '-L/nix/store/1x81mi97ycg58d15n0zfz49qhysyh9gd-protobuf-24.4/lib' [-Wunused-command-line-argument]                                                                                        
cpp: warning: argument unused during compilation: '-L/nix/store/55lkzxlbg2qapz6z3nv590fjv5f0p7sh-abseil-cpp-20240116.2/lib' [-Wunused-command-line-argument]                                                                                
cpp: warning: argument unused during compilation: '-L/nix/store/h723hb9m43lybmvfxkk6n7j4v664qy7b-python3-3.11.9/lib' [-Wunused-command-line-argument]                                                                                       
cpp: warning: argument unused during compilation: '-L/nix/store/1x81mi97ycg58d15n0zfz49qhysyh9gd-protobuf-24.4/lib' [-Wunused-command-line-argument]                                                                                        
cpp: warning: argument unused during compilation: '-L/nix/store/55lkzxlbg2qapz6z3nv590fjv5f0p7sh-abseil-cpp-20240116.2/lib' [-Wunused-command-line-argument]                                                                                
cpp: warning: argument unused during compilation: '-L/nix/store/h723hb9m43lybmvfxkk6n7j4v664qy7b-python3-3.11.9/lib' [-Wunused-command-line-argument]                                                                                       
cpp: warning: argument unused during compilation: '-L/nix/store/1x81mi97ycg58d15n0zfz49qhysyh9gd-protobuf-24.4/lib' [-Wunused-command-line-argument]                                                                                        
cpp: warning: argument unused during compilation: '-L/nix/store/55lkzxlbg2qapz6z3nv590fjv5f0p7sh-abseil-cpp-20240116.2/lib' [-Wunused-command-line-argument]                                                                                
cpp: warning: argument unused during compilation: '-L/nix/store/h723hb9m43lybmvfxkk6n7j4v664qy7b-python3-3.11.9/lib' [-Wunused-command-line-argument]                                                                                       
cpp: warning: argument unused during compilation: '-L/nix/store/wn7v2vhyyyi6clcyn0s9ixvl7d4d87ic-glibc-2.40-36/lib' [-Wunused-command-line-argument]                                                                                        
cpp: warning: argument unused during compilation: '-L/nix/store/4krab2h0hd4wvxxmscxrw21pl77j4i7j-gcc-13.3.0/lib/gcc/x86_64-unknown-linux-gnu/13.3.0' [-Wunused-command-line-argument]                                                       
cpp: warning: argument unused during compilation: '-L/nix/store/ybjcla5bhj8g1y84998pn4a2drfxybkv-gcc-13.3.0-lib/lib' [-Wunused-command-line-argument]                                                                                       
cpp: warning: argument unused during compilation: '-L/nix/store/4krab2h0hd4wvxxmscxrw21pl77j4i7j-gcc-13.3.0//lib' [-Wunused-command-line-argument]                                                                                          
cpp: warning: argument unused during compilation: '-L/nix/store/j8rzqx7farv0w3isp9z943zy437zk02f-gcc-13.3.0-libgcc/lib' [-Wunused-command-line-argument]                                                                                    
cpp: warning: argument unused during compilation: '-L/nix/store/2j35g928qczhj13kfi7yxm09wg2jiv14-clang-18.1.8-lib/lib' [-Wunused-command-line-argument]                                                                                     
                                                                                                                                                                                                                                            
                                                                                                                                                                                                                                            
================================================================================                                                                                                                                                            
= Started at 2024-12-23T23:37:32                                               =                                                                                                                                                            
= sys.argv = [                                                                 =                                                                                                                                                            
=   'back_to_shell_sol.py',                                                    =                                                                                                                                                            
= ]                                                                            =                                                                                                                                                            
================================================================================                                                                                                                                                            
2024-12-23T23:37:32:INFO:pwnlib.tubes.process.process.140272202976464:Stopped process './back_to_shell' (pid 181737)              

Since it's not an important warning I thought to just ignore it. This problem could happen on any system that wraps the cpp builtin in a weird way.

For now I'm targeting dev since it seems the most appropriate, but please tell me if I need to change it.

@Arusekk
Copy link
Member

Arusekk commented Dec 24, 2024

Thanks for the fix! I think this is sufficient and will be helpful.

I think you should also raise the same issue with nix itself, since these arguments (linker arguments and such) make no sense for preprocessing. The warning might become an error in future versions of GCC if they decide to change CLI handling to more strict, or flag the warning as defaulting to error. I think the current behaviour (printing just a warning) is pure courtesy of GCC; it could well error out on invalid and unknown options.

Another problem is whether Python depends in runtime on the C compiler. The nix package for full pwntools should include a C preprocessor at least, not necessarily a system-like compiler, but the error suggests that a full compiler is being used, not a stripped preprocessor.
(Pwntools producing binaries is deliberately trying to mimic a typical or minimal Linux distro so that the created ELF works in your target system. I do not think nix is either, so nix forcing pwntools into compiling for nix is quite counterproductive anyway.)

@sbancuz
Copy link
Author

sbancuz commented Dec 24, 2024

Thanks, I will definitely open an issue with nix for this as you are right; things like this should be fixed upstream.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants