204 shaares
DPKG
package manager for Debian
dpkg [option...] action
-i # Installs a Debian package file
-c # Lists the contents of
-I # Extracts package information
-r # Removes an installed package
-P # Removes & Purges an installed package named
-L # Gives a listing of all the files installed by
-s # Shows information on the installed package
-S # Return package names & files find in package database
--get-selections # Get the current status of
example
echo `` hold'' | dpkg --set-selections # Put on hold
DPKG-RECONFIGURE
dpkg-reconfigure # Reconfigures an installed package (see -f --frontend options)
APT
add repository
apt-add-repository ppa:lubuntu-desktop/ppa
add-apt-repository 'deb http://extras.ubuntu.com/ubuntu quantal main'
add-apt-repository 'deb-src http://extras.ubuntu.com/ubuntu quantal main'
apt-get install $pkg # Install packages
apt-get source $pkg # Get source code of installed & cached package
apt-get remove $pkg # Remove packages
apt-cache depends $pkg # Find dependencies of a packages
apt-cache search $pkg # Search in names of packages
apt-cache show $pkg # Shows description of availables packages & versions
apt-cache showpkg $pkg # Shows full description of packages
apt-cache policy $pkg # Shows source url repository of packages
apt-cache madison $pkg # Shows all available versions of packages
APT-MARK
apt-mark auto $pkg # Mark the given packages as automatically installed
apt-mark manual $pkg # Mark the given packages as manually installed
apt-mark hold $pkg # Mark a package as held back
apt-mark unhold $pkg # Unset a package set as held back
apt-mark showauto $pkg # Print the list of automatically installed packages
apt-mark showmanual $pkg # Print the list of manually installed packages
apt-mark showhold $pkg # Print the list of package on hold
example
apt-mark hold php7.4* # hold install & update for all packages started with 'php7.4'
APT-FILE
apt-get install apt-file && apt-file update # install & update files
apt-file search paplay # search which packages contains 'paplay'
BACKPORTS
apt-get install -t trusty-backports $PACKAGE # use backports to install packagecontrol
enable/disable
a2ensite $site_name # enable site
a2dissite $site_name # disable site
a2enconf $conf_name # enable configuration file
a2disconf $conf_name # enable configuration file
a2enmod $module_name # enable module
a2dismod $module_name # enable module
a2ctl
a2ctl configtest # test configurations
a2ctl status # show status
a2ctl fullstatus # shows fullstatus
a2ctl -l # list compiled modules
a2ctl -L # list available configuration directives
a2query
a2query -s $module_name # checks whether the site is enabled or return list of available sites
a2query -c $conf_name # checks whether the configuration is enabled or return list of available configurations
a2query -m $module_name # checks whether the module is enabled or return list of available modules
benchmark: ab
Simule 2000 utilisateurs qui effectueront des requĂȘtes entre toutes les 0 et 5 secondes pendant 10 minutes
# 5000 requests from 5 concurrent clients
ab -c 5 -n 5000 $url
# 2000 clients requests between 0-5s during 10mn
siege -d5 -r500 -c2000 -t10M $url
log
# ambau.ovh
<VirtualHost *:80>
ServerName ambau.ovh
ServerAlias www.ambau.ovh
ServerAdmin webmaster@ambau.ovh
<FilesMatch ".+\.ph(p[3457]?|t|tml)$">
SetHandler "proxy:unix:/run/php/php7.3-fpm.sock|fcgi://localhost"
</FilesMatch>
# PHP: SetEnv PHP_VALUE | PHP_ADMIN_VALUE : not rewrite by user
#SetEnv PHP_ADMIN_VALUE "session.gc_maxlifetime = 14400"
#SetEnv PHP_VALUE "upload_max_filesize = 100M"
#php_value upload_max_filesize 100M
DocumentRoot /var/share/www/ambau.ovh/html
<Directory /var/share/www/ambau.ovh/html>
Options -Indexes -MultiViews +FollowSymLinks
AllowOverride All
Require all granted
</Directory>
# Possible values include: debug, info, notice, warn, error, crit, alert, emerg.
LogLevel warn
#SetEnvIf Remote_Addr "::1" nolog
#SetEnvIf Remote_Addr "127\.0\.0\.1" nolog
#SetEnvIf Remote_Addr "10\.0\.0\.1/24" nolog
#SetEnvIf Remote_Addr "176\.31\.255\.134" nolog
#SetEnvIf Request_Method OPTIONS nolog
SetEnvIf X-Forwarded-For ".+" forwarded
CustomLog "|/usr/bin/logger -p local7.info -t ambau.ovh/apache" combined env=forwarded
#CustomLog "|/usr/bin/logger -p local7.info -t ambau.ovh/apache" combined env=!nolog
#CustomLog "|/usr/bin/logger --rfc3164 -p local7.info -t ambau.ovh/apache -n 176.31.255.134 --udp -P 514" combined env=!nolog
#CustomLog "|/usr/bin/logger --rfc3164 -t ambau.ovh/apache -p info -n 176.31.255.134 --udp -P 514" combined env=!nolog
#CustomLog ${APACHE_LOG_DIR}/ambau.ovh.log combined env=!nolog
ErrorLog "|/usr/bin/logger -p local7.err -t ambau.ovh/apache"
#ErrorLog "|/usr/bin/logger --rfc3164 -p local7.err -t ambau.ovh/apache -n 176.31.255.134 --udp -P 514"
#ErrorLog ${APACHE_LOG_DIR}/ambau.ovh.err
#Include conf-available/serve-cgi-bin.conf
</VirtualHost> get content from links - for shaarli
// use DOMXPath
function file_get_contents_utf8($url) {
$content = file_get_contents($url);
return mb_convert_encoding($content, 'UTF-8',
mb_detect_encoding($content, 'UTF-8, ISO-8859-1', true));
}
//if (empty($charset)) echo "EMPTY".'', PHP_EOL;
//$dom->loadHTMLFile($url, LIBXML_NOWARNING | LIBXML_NOERROR);
$url="http://code.ambau.ovh/snippets/bash_network.html";
$dom = new DOMDocument();
$html = file_get_contents_utf8($url);
$dom->loadHTML($html, LIBXML_NOWARNING | LIBXML_NOERROR);
$xpath = new DOMXPath($dom);
$html_data = array('title','tags','code');
// title
foreach($xpath->evaluate("//title") as $node) {
$html_data['title'] = $node->nodeValue;
}
// tags
foreach($xpath->evaluate("//body['class']") as $node) {
$html_data['tags'] = $node->getAttribute('class');
}
// description
foreach($xpath->evaluate("//code") as $node) {
$html_data['code'][] = $node->nodeValue;
}
// print
echo "".$html_data['title'].'', PHP_EOL;
echo "tags=".$html_data['tags'].'', PHP_EOL;
foreach($html_data['code'] as $code) echo ''.$code.'', PHP_EOL;
// use DOMDocument
$title = $dom->getElementsByTagName('title')->item(0);
if (!is_null($title)) echo ''.$title->nodeValue.'', PHP_EOL;
# tags
$node = $dom->getElementsByTagName('body')->item(0);
if ($node->hasAttribute('class')) {
$tags = $node->getAttribute('class');
echo "tags=$tags".'', PHP_EOL;
} else echo "no class attribute";
$code = ;
foreach ($dom->getElementsByTagName('code') as $node) { echo ''.$node->nodeValue.'', PHP_EOL; }IP
ip a / ip addr show # print informations about all interface
ip addr show dev <device> # print informations about specified device
ip -br addr show dev <device> # print brief informations about specified device
ip -4 a / ip -4 addr show # print informations about all interface for inet family
ip -6 a / ip -6 addr show # print informations about all interface for inet6 family
ip -4 -o route show to default # get device name for default IP v4 route
ip -6 -o route show to default # get device name for default IP v6 route
ip -br -4 -o address show dev <interface> | sed 's|.*\s\+\([0-9\.]\+\)/.*|\1|' # get ip v4 of given interface
ip -br -6 -o address show dev <interface> | sed 's|.*\s\+\([0-9a-z:]\+\)/128.*|\1|' # get ip v6 of given interface
NSTAT
Show open port
options
-a # all sockets (default connected)
-l # listening ports
-p # display the process
-n # numerical addresses (no DNS resolution)
-t # only TCP ports
-u # only UDP ports
tricks
netstat -pl | netstat -pla # listening process
netstat -plu # listening process for UDP
netstat -plt # listening process for TCP
netstat -pln # listening process with IP (no NDS resolution)
netstat -patn # process (listening or not) for TCP with IP (no NDS resolution)
netstat -plutn # show listening process for UDP & TCP with IP (no NDS resolution)
netstat -antup
NMAP
Scan network
tricks
# Scan from 192.168.1.0 to 192.168.1.255
nmap 192.168.1.0-10
# Scan with specified range of ports
nmap -p 81-1024 192.168.1.3
# Scan open ports, send a ICMP ECHO (ping) request
nmap -sP 192.168.1.*
# return all open TCP ports by sending SYN messages
nmap -sS $IP
# return all open UDP ports
nmap -sU $IP
# return informations about OS
nmap -O $IP
nmap -A -T4 $IP
# return potential version of OS
nmap -O --osscan-guess $IP
# Scan with a random mac address
nmap --spoof-mac B0:65:BD:01:01:01 192.168.1.3
TRICKS
show open ssh connection
netstat -n --protocol inet | grep ':22'
lsof -i -n | egrep 'ssh'
lsof -i -n | egrep 'sshd'
create mac address
mac=$(< /dev/urandom tr -dc a-z0-9 | head -c10 |sed 's/\(..\)\(..\)\(..\)\(..\)\(..\)/02:\1:\2:\3:\4:\5/')
resolution of domain name
nslookup $DOMAIN
get ip for eth0
ifconfig eth0 | sed -n 's|^[[:space:]]\+inet \(addr:\)\?\([0-9\.]\+\) .*|\2|p'
get ctid for eth0 (openVZ)
ifconfig eth0 | sed -n 's|^[[:space:]]\+inet \(addr:\)\?[0-9\.]\+\.\([0-9]\+\) .*|\2|p'
SCAN
arp
arp -ne -i wlan0 # scan interface wlan0 without dns & print in shell mode
arp-scan -lI wlan0 # scan the entire locanet interface wlan0
arp-scan -lI eth0 129.20.228.1/24 # scan the interface eth0 with a mask 0.0.0.31
arp-scan -I wlan0 192.168.0.100-192.168.0.200 # scan the locanet interface wlan0 with ips between 192.168.0.100 and 192.168.0.200
nmap
nmap -sP 192.168.0.1/24 # scan by pinging ip addresses with mask 0.0.0.255
nmap -e wlan0 -sP 192.168.0.100-199 # scan the interface wlan0 with ips between 192.168.0.100 and 192.168.0.200
nmap -e wlan0 -sP 192.168.0.,1,101 -oG $file # scan the interface wlan0 with ips 192.168.0.100 & print the result in grepable format to file
nmap -e wlan0 -sL 192.168.0.5,10-20 # List cached informations on ips : 192.168.0.5 & between 192.168.0.10 & 192.168.0.2
nc
nc -v -u -z -w 3 91.121.112.140 514 # test udp port open
WIFI
iwconfig wlo1 | iw dev wlo1 link # print technical informations
lshw -C network
iwlist scan # scan & print informations about wifi networks
nmcli connection show # show available connections about wifi networks
nmcli dev wifi