TVT618

Advanced Package Management in Kali Linux

Apr 26th, 2018
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.31 KB | None | 0 0
  1. Advanced Package Management in Kali Linux
  2. The Advanced Package Tool (APT) is how programs, libraries, documentation, and even the kernel itself are installed and managed on Kali and other Debian-based derivatives. APT often works so well that many users don’t pay any particular attention to it other than to perhaps search for and install programs and (hopefully) update their system regularly.
  3.  
  4. For most standard users, making use of APT this way is perfectly normal but we like to think that people who use Kali Linux are not standard users (in a good way) and so we are devoting this post to telling how you to get better use of APT and how to take advantage of the wide ecosystem of packages that are available, while keeping your Kali system stable and happy.
  5.  
  6. Many people will tell you that you should not rely on a package manager at all and instead, you should compile everything from scratch because you will learn more that way. While it’s certainly true that you will learn a lot, especially as you start out, building everything by hand will quickly devolve into tedium when you could be spending your time hacking or learning something new, preferably both.
  7.  
  8. In this post, we’ll show you how you can safely add additional package repositories to your Kali installation, how to upgrade and downgrade them, and how to ensure all of these repositories live in harmony. APT is very powerful and will evaluate the available packages from all sources as a whole when it formulates its solutions.
  9.  
  10. Adding Package Sources to Kali Linux
  11. If you want to make your future self happy, you should not directly edit /etc/apt/sources.list directly. For each new package repository you add to your system, create a new file with a descriptive name (like debian-unstable.list) under /etc/apt/sources.list.d/. By leaving the original sources.list file untouched, if Kali needs to update it, it won’t interrupt you during the update, asking you which version of the file to keep.
  12. In this post, we are going to add the Kali Bleeding-Edge repository and the Debian Unstable and Experimental repositories.
  13.  
  14. The kali-bleeding-edge Repository
  15. The kali-bleeding-edge repository contains a number of tools that are very popular and change very frequently (even daily). It would be impractical and time-consuming to manually create and test updated packages so the packages in this repository are generated automatically whenever the upstream source changes. On the positive side, it means you are never more than 24 hours behind the upstream project but on the downside, these packages are not tested so you need to be aware that the packages in this repository may break from time to time.
  16.  
  17. You can add the repo and update the list of available packages as follows:
  18. echo "deb http://http.kali.org/kali kali-bleeding-edge main contrib non-free" > /etc/apt/sources.list.d/bleeding-edge.list
  19. apt update
  20.  
  21. To install a package from kali-bleeding-edge, you need to append the repository name to the package name:
  22. apt install dnsrecon/kali-bleeding-edge
  23.  
  24. Fortunately, APT makes it an easy to downgrade back to the kali-rolling version of a particular package at any time, so there is no need to fear the packages in the kali-bleeding-edge repository. If you find that a package is broken in kali-bleeding-edge, you can revert back to the kali-rolling version in the same manner:
  25. apt install dnsrecon/kali-rolling
  26.  
  27. The Debian Unstable and Experimental Repositories
  28. Kali Linux is a derivative of Debian Testing, which has more up-to-date software than Debian Stable. For even more recent software, there is the Debian Unstable distribution, which is a rolling development version of Debian, containing the most recent packages. When you encounter a bug in a Debian package, there might be a fixed version in the Debian Unstable repository so it is a good idea to add it to your Kali system. As with kali-bleeding-edge, the packages in Unstable may break from time to time.
  29.  
  30. Debian Experimental is yet another repository that contains packages that are under development. The packages in this repository are very current but can also be very buggy, more so than kali-bleeding-edge or Debian Unstable. APT will only install packages from this repository if you explicitly request them and you can always downgrade if things don’t work out.
  31.  
  32. echo "deb http://ftp.debian.org/debian unstable main contrib non-free" > /etc/apt/sources.list.d/debian.list
  33. echo "deb http://deb.debian.org/debian experimental main" >> /etc/apt/sources.list.d/debian.list
  34. apt update
  35.  
  36. As with the kali-bleeding-edge packages, if you want to install packages from unstable or experimental, append the repository name to the end of the package name as shown below.
  37.  
  38. root@kali:~# apt install socat/experimental netperf/unstable
  39. Reading package lists... Done
  40. Building dependency tree
  41. Reading state information... Done
  42. Selected version '2.0.0~beta9-1' (Debian:experimental [amd64]) for 'socat'
  43. Selected version '2.6.0-2.1' (kali-rolling, Debian:unstable [amd64]) for 'netperf'
  44. The following NEW packages will be installed:
  45. netperf
  46. The following packages will be upgraded:
  47. socat
  48. 1 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
  49. Need to get 909 kB of archives.
  50. After this operation, 1,127 kB of additional disk space will be used.
  51. Get:1 http://kali.mirror.globo.tech/kali kali-rolling/non-free amd64 netperf amd64 2.6.0-2.1 [544 kB]
  52. Get:2 http://deb.debian.org/debian experimental/main amd64 socat amd64 2.0.0~beta9-1 [365 kB]
  53. Fetched 909 kB in 1s (555 kB/s)
  54. Reading changelogs... Done
  55. apt-listchanges: Mailing root: apt-listchanges: news for kali
  56. Selecting previously unselected package netperf.
  57. (Reading database ... 287650 files and directories currently installed.)
  58. Preparing to unpack .../netperf_2.6.0-2.1_amd64.deb ...
  59. Unpacking netperf (2.6.0-2.1) ...
  60. Preparing to unpack .../socat_2.0.0~beta9-1_amd64.deb ...
  61. Unpacking socat (2.0.0~beta9-1) over (1.7.3.2-1) ...
  62. Setting up socat (2.0.0~beta9-1) ...
  63. Processing triggers for systemd (234-3) ...
  64. Processing triggers for man-db (2.7.6.1-2) ...
  65. Setting up netperf (2.6.0-2.1) ...
  66. update-rc.d: We have no instructions for the netperf init script.
  67. update-rc.d: It looks like a network service, we disable it.
  68. Processing triggers for systemd (234-3) ...
  69.  
  70. Determining Package Priorities
  71. In order to determine what packages get installed, APT has priorities assigned for all package sources, with the highest priority number taking precedence. A package with a priority of 0 will never be installed and a package with a priority over 1000 will always be installed, even if it means downgrading the package.
  72.  
  73. This is all well and good for APT but how can you, the user, see what the priority is of a given package? Enter the little-known ‘apt-cache’ command and its ‘policy’ option, which displays all of your configured repositories and their priorities.
  74.  
  75. root@kali:~# apt-cache policy
  76. Package files:
  77. 100 /var/lib/dpkg/status
  78. release a=now
  79. 1 http://deb.debian.org/debian experimental/main amd64 Packages
  80. release o=Debian,a=experimental,n=experimental,l=Debian,c=main,b=amd64
  81. origin deb.debian.org
  82. 500 http://ftp.debian.org/debian unstable/non-free amd64 Packages
  83. release o=Debian,a=unstable,n=sid,l=Debian,c=non-free,b=amd64
  84. origin ftp.debian.org
  85. 500 http://ftp.debian.org/debian unstable/contrib amd64 Packages
  86. release o=Debian,a=unstable,n=sid,l=Debian,c=contrib,b=amd64
  87. origin ftp.debian.org
  88. 500 http://ftp.debian.org/debian unstable/main amd64 Packages
  89. release o=Debian,a=unstable,n=sid,l=Debian,c=main,b=amd64
  90. origin ftp.debian.org
  91. 100 http://http.kali.org/kali kali-bleeding-edge/main amd64 Packages
  92. release o=Kali,n=kali-bleeding-edge,c=main,b=amd64
  93. origin http.kali.org
  94. 990 http://http.kali.org/kali kali-rolling/contrib amd64 Packages
  95. release o=Kali,a=kali-rolling,n=kali-rolling,c=contrib,b=amd64
  96. origin http.kali.org
  97. 990 http://http.kali.org/kali kali-rolling/non-free amd64 Packages
  98. release o=Kali,a=kali-rolling,n=kali-rolling,c=non-free,b=amd64
  99. origin http.kali.org
  100. 990 http://http.kali.org/kali kali-rolling/main amd64 Packages
  101. release o=Kali,a=kali-rolling,n=kali-rolling,c=main,b=amd64
  102. origin http.kali.org
  103. Pinned packages:
  104.  
  105. You will note that kali-rolling, as the default distribution, has the highest priority at 990, meaning its packages take precedence over all others (which is what you want as a Kali user), followed by Debian unstable at 500, kali-bleeding-edge at 100, and lastly, experimental, with a lowly priority of 1. To see how these priorities apply to a given package, take a look at sqlmap.
  106.  
  107. root@kali:~# apt-cache policy sqlmap
  108. sqlmap:
  109. Installed: 1.1.9-1
  110. Candidate: 1.1.9-1
  111. Version table:
  112. 1.1.9+0~git1505273832.7de63a-1 100
  113. 100 http://http.kali.org/kali kali-bleeding-edge/main amd64 Packages
  114. *** 1.1.9-1 990
  115. 990 http://http.kali.org/kali kali-rolling/main amd64 Packages
  116. 500 http://ftp.debian.org/debian unstable/main amd64 Packages
  117. 100 /var/lib/dpkg/status
  118.  
  119. Even though the version of sqlmap in kali-bleeding-edge is newer, it will not be installed because it only has a priority of 100, versus the installed version, which has a priority of 990. It is for this reason that when you want to install a package from a different package repository, it needs to be requested explicitly.
  120.  
  121. root@kali:~# apt install sqlmap/kali-bleeding-edge
  122. Reading package lists... Done
  123. Building dependency tree
  124. Reading state information... Done
  125. Selected version '1.1.9+0~git1505273832.7de63a-1' (http.kali.org [all]) for 'sqlmap'
  126. The following packages will be upgraded:
  127. sqlmap
  128. 1 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
  129. Need to get 6,789 kB of archives.
  130. After this operation, 2,048 B of additional disk space will be used.
  131. Get:1 http://kali.mirror.globo.tech/kali kali-bleeding-edge/main amd64 sqlmap all 1.1.9+0~git1505273832.7de63a-1 [6,789 kB]
  132. Fetched 6,789 kB in 5s (1,192 kB/s)
  133. Reading changelogs... Done
  134. (Reading database ... 287587 files and directories currently installed.)
  135. Preparing to unpack .../sqlmap_1.1.9+0~git1505273832.7de63a-1_all.deb ...
  136. Unpacking sqlmap (1.1.9+0~git1505273832.7de63a-1) over (1.1.9-1) ...
  137. Setting up sqlmap (1.1.9+0~git1505273832.7de63a-1) ...
  138. Processing triggers for man-db (2.7.6.1-2) ...
  139.  
  140. APT Configuration
  141. Setting the Default Distribution
  142. Now that you have some extra repositories added to your system, you will want to begin exploring and installing new packages, but before you do, it’s a good idea to tell APT what your default distribution is, which for Kali Linux users, is “kali-rolling”. This way your system won’t upgrade to some other distribution without your consent. Configure your default distribution by adding “APT::Default-Release “kali-rolling”;” to /etc/apt/apt.conf.d/local:
  143. root@kali:~# cat /etc/apt/apt.conf.d/local
  144. APT::Default-Release "kali-rolling";
  145.  
  146. With your default distribution configured, any time you run ‘apt full-upgrade’, it will apply the upgrade to kali-rolling, helping keep your system stable.
  147.  
  148. Reducing Upgrade Prompts
  149. If you use any Debian derivative for a significant amount of time, you will come across a prompt while running ‘apt upgrade’ asking you about a configuration file and whether you want to keep the local version, use the new version, or compare them. More often than not, you will find yourself accepting the default, making these interruptions wasteful.
  150.  
  151. You can avoid these prompts by updating your /etc/apt/apt.conf.d/local file with ‘DPkg::options { “–force-confdef”; “–force-confold”; }’ as shown below. This line tells APT to try to choose by itself if the files have not changed (–force-confdef) and if the files are different, keep the existing version (–force-confold).
  152. root@kali:~# cat /etc/apt/apt.conf.d/local
  153. DPkg::options { "--force-confdef"; "--force-confold"; }
  154. APT::Default-Release "kali-rolling";
  155.  
  156. Pinning Package Versions
  157. Occasionally, you will find some application that needs a specific version of a particular package and will not work with any other. Other times, an update to one package might adversely affect other tools. This happened to us recently with an update to the devscripts package, which was preventing us from building Kali packages.
  158.  
  159. Fortunately, APT allows you to pin a package to a particular version by setting its priority to 1001 in /etc/apt/preferences. For example, to tell APT to hold the devscripts package at version 2.16.x, you would add the following
  160. Package: devscripts
  161. Pin: version 2.16.*
  162. Pin-Priority: 1001
  163.  
  164. Additional Resources
  165. In this post, Kali Linux team have only been able to scratch the surface of how you can extend APT far beyond the default Kali or Debian ecosystem. The solver algorithms are very effective and running into issues is rare, so you need not fear exploring other repositories. To learn more about APT and how to bend it to your will, we encourage you to refer to Kali Linux Revealed and The Debian Administrator’s Handbook, both of which contain a wealth of information, tips, and tricks.
  166.  
  167. From Kali Linux https://www.kali.org/tutorials/advanced-package-management-in-kali-linux/
Advertisement
Add Comment
Please, Sign In to add comment