Git Product home page Git Product logo

eriksjolund / empty-argv-segfault-check Goto Github PK

View Code? Open in Web Editor NEW
3.0 3.0 1.0 19 KB

Test if an executable segfaults when started with an empty argv. The script may be used as a vulnerability-scanner to find setuid executables having buggy code (but it will probably not find any direct security vulnerabilities).

License: MIT License

CMake 39.76% Shell 48.79% C++ 11.45%
security segfault setuid vulnerability-scanners

empty-argv-segfault-check's Introduction

empty-argv-segfault-check

Test if an executable segfaults when started with an empty argv. The script may be used as a vulnerability-scanner to find setuid executables having buggy code (but it will probably not find any direct security vulnerabilities).

Installation

ubuntu@laptop:~$ mkdir /tmp/build
ubuntu@laptop:~$ mkdir /tmp/install
ubuntu@laptop:~$ cd /tmp/build
ubuntu@laptop:/tmp/build$ cmake -DCMAKE_INSTALL_PREFIX=/tmp/install ~/empty-argv-segfault-check/ && make && make install
-- The CXX compiler identification is GNU 7.2.0
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /tmp/build
Scanning dependencies of target empty-argv-segfault-check
[ 50%] Building CXX object CMakeFiles/empty-argv-segfault-check.dir/main.cc.o
[100%] Linking CXX executable empty-argv-segfault-check
[100%] Built target empty-argv-segfault-check
[100%] Built target empty-argv-segfault-check
Install the project...
-- Install configuration: ""
-- Installing: /tmp/install/bin/empty-argv-segfault-check
-- Installing: /tmp/install/bin/segfault_detect.sh
-- Installing: /tmp/install/bin/find-executables.sh
ubuntu@laptop:/tmp/build$ 

Usage

Find all executables

ubuntu@laptop:/tmp$ /tmp/install/bin/find-executables.sh > /tmp/all.txt
[sudo] password for ubuntu: 
ubuntu@laptop:/tmp$ 

Find all setuid executables

ubuntu@laptop:/tmp$ /tmp/install/bin/find-executables.sh setuid > /tmp/all-setuid.txt
[sudo] password for ubuntu: 
ubuntu@laptop:/tmp$ 

Starting executables with an empty argv and see if they segfaults

Note, starting executables might have side effects. If you want to start all the executables found on the system you better do this on a separate test user account or even better on a virtual machine.

test@laptop:/tmp$ /tmp/install/bin/segfault_detect.sh /tmp/all.txt 

The result is written to a temporary file in /tmp/

test@laptop:/tmp$ ls -ltr /tmp/result.*
/tmp/result.3otWy.txt

To list the executables that segfaulted:

test@laptop:/tmp$ cat /tmp/result.3otWy.txt
/usr/bin/prog1
/usr/bin/prog2
/usr/bin/prog3

FAQ

Why does some executables segfault when started with an empty argument list?

When argc is 0, argv[0] is NULL. Probably, the most common cause of the segfault is the dereferencing of argv[0]. A lot of programs falsely assume that argv[0] contains the program name without verifying that argc is not equal to 0.

main(int argc, char *argv[]) {
  if (argc != 2) {
    fprintf(stderr, "Usage: %s filepath\n", argv[0]);
    exit(1);
  }

Discussion: #2

Can vulnerabilities be found with empty-argv-segfault-check?

Probably not, as the program will just end directly when the null pointer is dereferenced. The interesting case regarding security is finding segfaulting executables that have the setuid bit set. Such executables run under a different User ID than the one of the user who launched it.

At least empty-argv-segfault-check could be used to find setuid executables that are not of the highest code quality. They may contain other bugs.

Discussion: #3

Are there normal circumstances where argv[0] isn't the name of the program being run?

This question has an answer at Stackoverflow: When can argv[0] have null?

empty-argv-segfault-check's People

Contributors

brlin-tw avatar eriksjolund avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

brlin-tw

empty-argv-segfault-check's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.