简体   繁体   English

Debian:列出所有用户安装的软件包?

[英]Debian: Listing all user-installed packages?

For a cyber security competition I participate in, I'm given a Debian virtual machine with many packages installed and asked to clean extraneous or malicious packages.在我参加的网络安全竞赛中,我得到了一台 Debian 虚拟机,其中安装了许多软件包,并要求我清理无关或恶意的软件包。

In the past, I've used dpkg -l | grep [searchterm]过去,我使用过dpkg -l | grep [searchterm] dpkg -l | grep [searchterm] and a list of common packages to preform this task. dpkg -l | grep [searchterm]和执行此任务的常用包列表。 However, this is extremely inefficient and time-consuming.然而,这是极其低效和耗时的。

To speed up my task, is there any way to search through the list of packages installed on a system for which processes have been installed by a user and are not system "default" packages?为了加快我的任务,有什么方法可以搜索系统上安装的软件包列表,其中用户安装了哪些进程并且不是系统“默认”软件包?

This command may shorten your work:此命令可能会缩短您的工作:

apt-mark showmanual

It is supposed to show what packages were installed "manually".它应该显示“手动”安装了哪些软件包。 It is not 100% reliable though, as many automatically installed packages are flagged as manually installed (because of reasons too long to describe here).但是,它不是 100% 可靠的,因为许多自动安装的软件包被标记为手动安装(因为这里描述的原因太长了)。

You may also (if allowed) run security tools such as clamav and/or rkhunter to scan your computer for malicious programs.您还可以(如果允许)运行安全工具,例如clamav和/或rkhunter来扫描您的计算机以查找恶意程序。

Below is a line from a "health" script I run on my desktop every night.下面是我每天晚上在桌面上运行的“健康”脚本中的一行。 Besides gathering information from sensors, network usage, HDD temperature, etc. it also gets a list of all the software I've installed manually from the command line.除了从传感器、网络使用情况、硬盘温度等收集信息外,它还从命令行获取我手动安装的所有软件的列表。

I'm running Kubuntu 14.04.5 (Trusty) at the moment and I don't know the details of any differences between Ubuntu and Debian's package management but hopefully this will work for you as well as it does for me.我目前正在运行 Kubuntu 14.04.5 (Trusty),我不知道 Ubuntu 和 Debian 包管理之间任何差异的细节,但希望这对你和我一样有用。

( zcat $( ls -tr /var/log/apt/history.log*.gz ) ; cat /var/log/apt/history.log ) | egrep '^(Start-Date:|Commandline:)' | grep -v aptdaemon | egrep '^Commandline:' | egrep 'install' 1>>installed_packages.txt

All Packages所有套餐

Most all the code that I found for this question used a search from the history log:我为这个问题找到的大多数代码都使用了历史日志中的搜索:

$ cat /var/log/apt/history.log | grep 'apt-get install '

or listed all Debian Packages installed on the machine:或列出机器上安装的所有 Debian 软件包:

$ dpkg --get-selections

Manually Installed手动安装

I found the above answers to be inadequate as my history log was incomplete and I didn't want to do the work to separate built-in packages with manually installed packages.我发现上述答案不够充分,因为我的历史日志不完整,而且我不想将内置包与手动安装的包分开。 However, this solution did the trick of showing only manually initiated installed packages.然而,这个解决方案做到了只显示手动启动的安装包的技巧。 This one uses the log: /var/log/dpkg.log , and it should be executed as a bash script.这个使用日志: /var/log/dpkg.log ,它应该作为 bash 脚本执行。

#!/usr/bin/env bash
parse_dpkg_log() {
  {
    for FN in `ls -1 /var/log/dpkg.log*` ; do
      CMD="cat"
      [ ${FN##*.} == "gz" ] && CMD="zcat" 
      $CMD $FN | egrep "[0-9] install" | awk '{print $4}' \
        | awk -F":" '{print $1}'
    done
  } | sort | uniq
}

list_installed=$(parse_dpkg_log)
list_manual=$(apt-mark showmanual | sort)
comm -12 <(echo "$list_installed") <(echo "$list_manual")

I found the code here: https://gist.github.com/UniIsland/8878469我在这里找到了代码: https : //gist.github.com/UniIsland/8878469

This takes into account also packages installed with aptitude (not only apt install or apt-get install , like Benny Hill's answer which I based on):这还考虑了使用aptitude安装的软件包(不仅是apt installapt-get install ,就像我所基于的 Benny Hill 的答案):

( ( zcat $( ls -tr /var/log/apt/history.log*.gz ) ; cat /var/log/apt/history.log ) | egrep '^(Start-Date:|Commandline:)' | grep -v aptdaemon ; ( zcat $( ls -tr /var/log/aptitude.*.gz ) ; cat /var/log/aptitude ) ) | egrep '^Commandline:.*install|^\[INSTALL\]' | sed 's#Commandline: ##' | awk '/INSTALL/ { print $2 }; !/INSTALL/ { print $0 }; ' 1>installed_packages.txt

Example output (the last line comes from aptitude logs):示例输出(最后一行来自 aptitude 日志):

apt-get install nodejs
apt install tidy
mc:amd64

You may also look at the file /var/lib/apt/extended_states.您还可以查看文件 /var/lib/apt/extended_states。

cat /var/lib/apt/extended_states | grep -B2 'Auto-Installed: 0'

This is useful if you want to know what was installed on an old partition.如果您想知道旧分区上安装了什么,这很有用。

The following Bash command works for me in Debian 10 (buster).以下 Bash 命令在 Debian 10 (buster) 中对我有用。 It prints all manually installed packages minus the ones that came from your Debian installation (in other words, the packages that you installed with apt install ):它打印所有手动安装的软件包,减去来自您的 Debian 安装的软件包(换句话说,您使用apt install的软件包):

sudo grep -oP "Unpacking \K[^: ]+" /var/log/installer/syslog \
  | sort -u | comm -13 /dev/stdin <(apt-mark showmanual | sort)

sudo is needed to search through /var/log/installer/syslog .需要sudo来搜索/var/log/installer/syslog You could also save this installer package list somewhere else if you don't want to use sudo every time.如果您不想每次都使用sudo也可以将此安装程序包列表保存在其他地方。

Someone wrote a program generate a list of all packages manually installed (by users, by admin/root, or both), as determined by the Debian package system.有人编写了一个程序,生成一个由 Debian 软件包系统确定的手动安装的所有软件包的列表(由用户、管理员/root 或两者)。 It inspects Debian's apt-history log, and then combines the reports from the apt-mark program.它检查 Debian 的 apt-history 日志,然后结合来自apt-mark程序的报告。 Apt-mark includes packages which were manually installed via use of the 'dpkg' system directly by users, not just ones installed via users through their package manager utility (Apt, Synaptic, Software Center, etc.). Apt-mark 包括用户直接使用“dpkg”系统手动安装的软件包,而不仅仅是用户通过他们的软件包管理器实用程序(Apt、Synaptic、软件中心等)安装的软件包。 If you lack the apt-mark utility, you can tell it do just do the history inspection instead.如果您缺少 apt-mark 实用程序,您可以告诉它只执行历史检查。

See the GitHub page .请参阅GitHub 页面

List User Installed Debian Packages Utility列出用户安装的 Debian 软件包实用程序

List all packages manually installed (by users, by admin/root, or both), as determined by the Debian package system.列出由 Debian 软件包系统确定的所有手动安装的软件包(由用户、管理员/root 或两者)。

I dont know if it's possible to distiguich between user installation and default package installation, because the only way to install package is to have ROOT privillages.我不知道是否可以在用户安装和默认包安装之间进行区分,因为安装包的唯一方法是拥有ROOT权限。 but you cat get all package installed and their status in one file by executing this command但是您可以通过执行此命令将所有软件包及其状态都安装到一个文件中

dpkg --get-selections > installed_packages.txt

An older question but a solution I came up with after finding this and a couple of other questions for a slightly different task.一个较旧的问题,但我在找到这个问题和其他几个稍微不同的任务后想出了一个解决方案。 Trying to keep up to date a list of installed packages for system rebuilds.尝试更新系统重建的已安装软件包列表。 I found the following works pretty well:我发现以下效果很好:

comm -12 <(apt list --installed 2> /dev/null | cut -d '/' -f 1 | sort) <(history | grep -e "apt\(-get\)\? install" | grep -v -e "grep -e" | grep -v "./" | cut -d ' ' -f10 | sort)

This takes the list of all installed packages and compares to the history for packages being installed.这会获取所有已安装软件包的列表,并与正在安装的软件包的历史记录进行比较。

I'm assuming that packages are not being installed by evil actors trying to hide their tracks.我假设恶意演员没有安装软件包,试图隐藏他们的踪迹。 Also a slightly nasty command apt list in a script however it does seem to work for now.脚本中还有一个有点讨厌的命令 apt list 但它现在似乎确实有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM