Build a recovery toolkit

Source: Internet
Author: User

Introduction

All security guides recommend you shoshould have a security audit toolkit (or forensic toolkit or recovery toolkit ). this toolkit is constituted by a set of static-linked binaries (grep, w, netstat, ls, nc, strace, ps... Etc). The problem it that these security guides tell you to build this toolkit but never show you how to do it (they just tell it can be really difficult ...). In this article I will explain why we need this toolkit then I will show how to build it.

Note:The "build the toolkit" part of this article uses Apt-getPackage installer (for Debian-like distribs). I tested this code with success on Ubuntu, and with Debian (however some package are different and the described method may not always work ).

 

Why a recovery toolkit?

If an attacker had gain a superuser access into your system, he cocould have install a malware iike a trojan or a rootkit. Therefore you cannot trust anything on your system.SuOrLoginBinaries cocould have been replaced by his own tool to grab your passwords. Other trojan can directly attack shared library meaning that even newly compiled code may be dangerous.
The other use of this toolkit is to "repair after an accident". A single wrong command is enough to damage important binaries or shared libraries (for exampleRm-rOn the wrong folder ...).
This toolkit must be mounted on a read-only file-system and cocould be used by rootkit hunting tools suchChkrootkit.
It is also important to notice this toolkit is constituted of statically linked binaries. We cannot rely on the system shared libraries if the system is already upted.

Build the toolkit.

Note:The total size of the binaries + sources is about 500 Mo. The binaries size alone is less then 50 Mo.
Prerequisite:Create a folder where you will install your toolkit.
mkdir -p audit/src
mkdir -p audit/bin
You need to install the dpkg dev package.
apt-get  install dpkg-dev
The core binaries:

  1. Apt-get source coreutils audit/src
  2. Cd audit/src/coreutils-x.x # replace x by the package version
  3. ./Configure
  4. Make CC = "gcc-static-std = gnu99 ″
  5. Cp src/cat "../bin"
  6. Cp src/chmod "../bin"
  7. Cp src/chown "../bin"
  8. Cp src/cp "../bin"
  9. Cp src/cut "../bin"
  10. Cp src/dd "../bin"
  11. Cp src/df "../bin"
  12. Cp src/du "../bin"
  13. Cp src/echo "../bin"
  14. Cp src/head "../bin"
  15. Cp src/id "../bin"
  16. Cp src/ln "../bin"
  17. Cp src/ls "../bin"
  18. Cp src/md5sum "../bin"
  19. Cp src/mkdir "../bin"
  20. Cp src/mknod "../bin"
  21. Cp src/mv "../bin"
  22. Cp src/pwd "../bin"
  23. Cp src/readlink "../bin"
  24. Cp src/rm "../bin"
  25. Cp src/stat "../bin"
  26. Cp src/sha512sum "../bin"
  27. Cp src/su "../bin"
  28. Cp src/tail "../bin"
  29. Cp src/touch "../bin"
  30. Cp src/uname "../bin"
  31. Cp src/wc "../bin"
  32. Cp src/who "../bin"
  33. # These are essenessenbut there are more in the src folder

The proc binaries:

  1. Apt-get install libncurses-dev # required to build top
  2. Apt-get source procps audit/src
  3. Cd audit/src/procps-xxx # replace xxxx by the package version
  4. Make SHARED = 0 CC = 'gcc-static'
  5. Cp "free" "../bin"
  6. Cp "kill" "../bin"
  7. Cp "ps/ps" "../bin"
  8. Cp "top" "../bin"
  9. Cp "uptime" "../bin"
  10. Cp "vmstat" "../bin"
  11. Cp "w" "../bin"

The net-tools binaries:

  1. Apt-get source net-tools audit/src
  2. Cd audit/src/net-tools-xxx # replace xxxx by the package version
  3. Sed-I's @ default: @ & \ n break; @ 'lib/inet_sr.c
  4. Make config # Keep default config by answering [enter] to all prompts
  5. Sed-I's | # define HAVE_AFX25 1 | # define HAVE_HWX25 0 | 'config. h # you probably do not need X.25 protocol support
  6. Sed-I's | # define HAVE_HWX25 1 | # define HAVE_HWX25 0 | 'config. h
  7. # We needed to change to 0 values for HAVE_AFX25 and HAVE_HWX25 so it will compile on ubuntu
  8. # To avoid x25_sr.c: 80: error: 'x25 _ address 'undeclared (first use in this function)
  9. # If someone has found a better way do not hesitate to comment this article!
  10. Make CC = "gcc-static" ifconfig netstat arp route
  11. Cp "arp" "THYLACINE_OUTPUT_PATH/../bin "#
  12. Cp "ifconfig" "../bin"
  13. Cp "netstat" "../bin"
  14. Cp "route" "../bin"

The gawk binaries:

  1. Apt-get source gawk audit/src
  2. Cd audit/src/gawk-xxx # replace xxxx by the package version
  3. LDFLAGS = "-static" sh./configure # Static compiling is not always easy...
  4. Make LDFLAGS = "-static"
  5. Cp "gawk" "../bin"
  6. Ln-s "../bin/gawk" "../bin/awk"

The grep binaries:

  1. Apt-get source grep audit/src
  2. Cd audit/src/grep-xxx # replace xxxx by the package version
  3. ./Configure
  4. Make CC = "gcc-static"
  5. Cp "src/grep" "../bin"
  6. Cp "src/egrep" "../bin"

The lsof binary:

  1. Apt-get source lsof audit/src
  2. Cd audit/src/lsof-xxx # replace xxxx by the package version
  3. ./Configure-n linux
  4. Make CC = "gcc-static"
  5. Cp "lsof" "../bin"

The strace binary:

  1. Apt-get source strace audit/src
  2. Cd audit/src/strace-xxx # replace xxxx by the package version
  3. ./Configure
  4. Make CC = "gcc-static"
  5. Cp "strace" "../bin"

The sed binarie:

  1. Apt-get source sed audit/src
  2. Cd audit/src/sed-xxx # replace xxxx by the package version
  3. ./Configure
  4. Make CC = "gcc-static"
  5. Cp "sed/sed" "../bin"

The netcat binary:

  1. Apt-get source netcat audit/src
  2. Cd audit/src/netcat-xxx # replace xxxx by the package version
  3. Sed-I 1i "# include \" resolv. h \ "" netcat. c # Why is it always so difficult to compile source code...
  4. Make linux
  5. Cp "nc" "../bin"

The binutils binaries:

  1. Apt-get source binutils audit/src
  2. Cd audit/src/binutils-xxx # replace xxxx by the package version
  3. ./Configure
  4. Make LDFLAGS = "-all-static" &> make. log # CC = "gcc-static" does not work here
  5. Cp "binutils/strings" "../bin"
  6. # More binaries in there, pick the ones you want

The findutils binaries:

  1. Apt-get source findutils audit/src
  2. Cd audit/src/findutils-xxx # replace xxxx by the package version
  3. ./Configure
  4. Make CC = "gcc-static"
  5. Cp "find/find" "../bin"
  6. Cp "locate/locate" "../bin"
  7. Cp "xargs/xargs" "../bin"

 

Finally

We finished building our toolkit. Remember you shoshould keep this toolkit (at least the bin folder) on a separate read-only file-system (like a CD ).
You may want to verify that your binaries are really static. UseLddCommand for that.
ldd audit/bin/*
Shocould echo that all tools aren't dynamic binaries

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.