-*-outline-*- #+OPTIONS: \n:t ^:{} * by name ** anydesk gratuit jusqu'à 3 postes pour accéder sans autorisation préalable, il suffit de mettre un mot de pass. ** apache *** how to test the configuration apachectl configtest apachectl -t ** apparmor *** intro Some processes are monitored by AppArmor and their actions can be restricted to their AppArmor profile. For example : access to certain paths, or execution of certain commands, or certain kernel capabilities. If the profile doesn't allow, the user gets a permission denied. Example : tcpdump can't read or write files not ending with .pcap. *** log file apparmor actions are logged in /var/log/syslog with the audit facility *** tools **** aa-status get the actual status of aa, useful for introspection as some profiles are not necessarily on disk files **** aa-genprof this will monitor a process and help you defined a profile interactively by answering simple questions like : this process tries to access this ressource, allow/deny? **** aa-logprof this helps to update the profile in case the executable changes -update- by reading the audit logs. If new actions or paths are accessed it will prompt you and update the profile accordingly **** apparmor_parser -r if you manually modify a profile, run apparmor_parser for it to take effect. ** apt *** automatic yes apt-get -y install *** sources.lst **** explication 1. 2. 3. 4. deb http://ftp.debian.org/debian/ jessie main 1. deb ou deb-src 2. url du dépot 3. version de debian 4. filtre sur les paquets (contrib, nonfree etc.) **** fichier par défaut officiel https://wiki.debian.org/SourcesList#Example_sources.list **** debug symbols ajouter cette source deb http://deb.debian.org/debian-debug/ buster-debug main puis installer le paquet avec le suffixe -dbgsym **** source repos /etc/apt/sources.list.d/official-source-repositories.list *** show only the description of package in the output of apt-cache show apt-cache show | grep-dctrl -s Description-en - grep-dctrl is a grep that is specialized to apt files format. it is provided by the dctrl-tools package *** remove unused packages apt-get autoremove *** pourquoi ce paquet est installé apt-cache rdepends ou bien apt rdepends affichera les paquets qui ont pu installé celui-ci, soit comme dépendance, soit comme suggestion (recommendation) *** lister tous les fichiers d'un paquet non installé apt-file show *** ce paquet dépend de apt-cache depends *** lister les paquets cassés apt-get check *** This must be accepted explicitly before updates for this repository can be applied. see apt-secure(8) manpage for details. You need to run apt-get update with the --allow-releasinfo-change flag apt-get update --allow-releaseinfo-change *** download w/o installing apt-get download ** aptitude *** why aptitude why tells why a package got installed. *** understanding the output of aptitude commands **** state|action|installation mode|trust first char is state. second char is the action to be done third char is how the package was installed fourth char is package trustworthness **** state i : installed c : deleted, config files remain p : purged or never installed v : virtual B : broken dependencies C : half-configured (installation aborted) H : half-installed (installation aborted) W : triggers awaited T : triggers pending **** Action i : install d : delete p : purge u : upgrade h : hold (won't upgrade) F : Forbid to upgrade r : reinstall B : broken (don't install/reinstall/update until you fix this) **** installation mode A : automatic **** trust U : untrusted *** search **** search terms every parameter is a criterium criteria are OR'd so search ~N edit is two parameters, thus it will search all New package + all packages that match edit but search '~N edit' will search for new packages that match edit. **** terms ~M automatically installed ~b broken ~c config files only ~D list of packages needed by , called dependencies ~d search in descriptions ~n search in names (default) ~g not required by any manually installed package ~i installed packages ~m maintained by maintainer ~N New packages (never interacted with or marked as seen) ~o obsolete ~P search packages that provide ~R list packages that depend on ~U upgradable (installed and can be upgraded) ~v search for virtual packages ** ar *** invocation ar [] *** redirect output to stdout p. This is useful to use it as an input to tar for further processing. ** augtool *** whatis edit configuration files programmatically *** changing configuration from the command line 17:28:13 ~/DOCUMENTS/INTERNE/MESSAGERIE -1- $ augtool get /files/home/ychaouche/.ssh/config/Host[10] /files/home/ychaouche/.ssh/config/Host[10] = labonedjma.net 17:29:53 ~/DOCUMENTS/INTERNE/MESSAGERIE -1- $ augtool set /files/home/ychaouche/.ssh/config/Host[10] labonedjma Saved 1 file(s) 17:29:59 ~/DOCUMENTS/INTERNE/MESSAGERIE -1- $ augtool get /files/home/ychaouche/.ssh/config/Host[10] /files/home/ychaouche/.ssh/config/Host[10] = labonedjma 17:30:02 ~/DOCUMENTS/INTERNE/MESSAGERIE -1- $ *** it's also an interactive tool sudo augtool augtool> set /files/etc/ssh/sshd_config/PermitRootLogin no augtool> save augtool> quit ** avconv *** disable color in output AV_LOG_FORCE_NOCOLOR=1 avconv ... *** extract part of a video/audio ffmpeg -i input.mp4 -ss 00:09:23 -t 33 -c copy output.mp4 extracts 33 seconds starting from 09:23 ** awk *** invoking awk **** specifying program text program text w/ -e **** specifying program file program file w/ -f **** specifying the field separator -F will let you specify the field separator. **** shebang #!/usr/bin/gawk -f **** passing in variables -v var1=val2 var2=val2 etc. access them directly in the script, w/o using the $ sign *** printing specific things **** print last column {print $NF} **** print a captured group I want to capture the Duration of a video, this is from the output of ffprobe on a specific file that has a strange structure... The trick is then to use match($0,pattern,array) then reference the matching group with the array's indice. pattern : without quotes, without escaping any special characters like parens, brackets etc. warning : this only works with gawk ychaouche#ychaouche-PC 16:29:31 ~/VIDEOS/SCREENCASTS $ ffprobeoutput="Facebook: https Duration: 00:00:46.73, start: 0.000000, bitrate: 869 kb/s" ychaouche#ychaouche-PC 16:29:39 ~/VIDEOS/SCREENCASTS $ echo $ffprobeoutput Facebook: https Duration: 00:00:46.73, start: 0.000000, bitrate: 869 kb/s ychaouche#ychaouche-PC 16:35:24 ~/VIDEOS/SCREENCASTS $ echo $ffprobeoutput | awk 'match($0,/Duration: ([^,]+),/,A) {print A[1]}' 00:00:46.73 ychaouche#ychaouche-PC 16:35:27 ~/VIDEOS/SCREENCASTS $ **** print the number of lines awk 'END {print NR}' **** print last record awk 'END {print}' You can also change the record separator if records are separated with a specific pattern. For example, here's how to display last worklog.summary entry : alias notes.worklog.last='awk -v RS="\n\\\*" "END {print}" ~/NOTES/LOG/worklog.summary' 14:38:01 ~ -2- $ notes.worklog.last Lundi 19 Septembre 2022 - DNS override 14:57:09 ~ -2- $ **** select rows with a specific field value $3 ~ // {do something} $3 ~ // # will only print rows with in third field. $3 ~ "part of a string" # joker is implied with ~ **** nothing is printed don't forget to use print; **** too many lines printed don't do this $0 ~ regex { print($0,"matches"); } do this $0 ~ regex { print($0,"matches"); } the first is equivalent to $0 ~ regex {print} {print($0,"matches"), which is why all lines are printed as matching (because there's no pattern. **** emulate tail there is no easy way **** negative group matching with egrep -P you can relay=(?!127.0.0.1|local) with awk you may /^relay=/ && !/^relay=(127\.0\.0\.1|local)$/ **** printing an array for (key in my_dict) { print key ": " my_dict[key] } **** print the UA out of HTTPD logs the trick is to use '"' as a delimiter, then get the sixth field root@messagerie-prep[10.10.10.19] ~ # tail -f /var/log/apache2/roundcube.access.1 | awk -F\" '!/192.168|172.16|::1/ {print $1,$6}' 154.121.70.1 - - [13/Aug/2024:16:57:38 +0100] - 105.96.92.53 - - [13/Aug/2024:16:57:42 +0100] Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36 105.96.36.176 - - [13/Aug/2024:16:57:50 +0100] Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0 41.104.176.151 - - [13/Aug/2024:16:58:03 +0100] Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0 41.104.176.151 - - [13/Aug/2024:16:58:04 +0100] Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0 41.101.98.53 - - [13/Aug/2024:16:58:06 +0100] Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36 154.121.70.1 - - [13/Aug/2024:16:58:10 +0100] Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36 OPR/112.0.0.0 (Edition cdf) 41.98.231.172 - - [13/Aug/2024:16:58:12 +0100] Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36 197.201.235.26 - - [13/Aug/2024:16:58:14 +0100] Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36 Edg/127.0.0.0 LikeWise/95.6.5696.53 105.96.94.99 - - [13/Aug/2024:16:58:16 +0100] Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36 154.121.70.1 - - [13/Aug/2024:16:58:17 +0100] Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36 OPR/112.0.0.0 (Edition cdf) 105.110.155.239 - - [13/Aug/2024:16:58:19 +0100] Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36 105.96.92.53 - - [13/Aug/2024:16:58:21 +0100] Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36 105.96.12.180 - - [13/Aug/2024:16:58:22 +0100] Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:128.0) Gecko/20100101 Firefox/128.0 105.96.109.61 - - [13/Aug/2024:16:58:24 +0100] Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome *** matching **** matching a string containing meta-characters use index() instead of the ~ operator or match. **** matching regexes defined in user variables put regex w/o the / in between quotes like this : BEGIN { regex="([[:digit:]]{1,3}\\.){3}[[:digit:]]{1,3}"; } {if (match($0,regex,A)) {...} } *** removing things ***** remove first/last character ***** remove blank lines from a file awk NF file be careful : the file shouldn't contain \r chars. Otherwise, use a tr -d "\r" < file before. *** strings and regexes **** strings vs regexes and the \\ problem "\." is not a valid string "\\." is a valid string, it will be seen as "\." by the regex functions **** strings ***** concatenate with space, and probably add \n if adding $0 line = line $0 "\n" ***** formatting ****** numbers %06.2f 6 is the for the whole number, not just the natural part. ****** strings with variables (template strings) use sprintf like this: command=sprintf("pretty.ua '%s'",uastring); command | getline var; close(command) **** regexes ***** how to write regexes "" can produce errors // is the best fit for regexes ***** gawk is ERE mawk is basic regexes only gawk is extended regexes, with a few exceptions \y matches beginning or end of a word \w[ord] constituent (alnum + _) \W is [^\W] \s whitespace \S = [^\s] [:alnum:] [:alpha:] [:punct:] ***** no escaping necessary parens, + etc. need not be escaped ***** ignore case awk -v IGNORECASE=1 or, you can use tolower on strings you want to compare. ***** removing all meta-characters from a string gsub(/[$^*()+\[\]{}.?\\|]/,"\\\\&",task); *** communicating with the shell **** sending output to a pipe ***** example root@messagerie-principale[10.10.10.19] ~ # gawk -F: -e '{print $1 | "sort"}' /etc/passwd amavis backup bidon bin clamav daemon Debian-exim debian-spamd dovecot dovenull games glances gnats irc list lp mail man messagebus mysql news nobody ntp opendkim postfix proxy root serveur sshd statd sync sys systemd-bus-proxy systemd-network systemd-resolve systemd-timesync uucp vmail www-data root@messagerie-principale[10.10.10.19] ~ # ***** explanation this is because all output of print is piped to the sort command, which output is delivered at the end. **** getting input from a pipe ***** don't use getline ****** here's how to not use getline command = "cmd " var1 " " var2; command | getline x; close(command); will put the result of cmd var1 var2 in x. ****** close the pipe we need to close the pipe, otherwise next call to getline won't read (EOF or error). command = " ... "; command | getline var; close(command); ****** gl form ="undefined"; " " args | getline ; close(" " args); fflush() } ****** example 1 example where =country and =mygeoip (from mailcop-filter) : awk '{country="undef"; "mygeoip " $7 | getline country; close("mygeoip " $7); printf "%s %s %s %-40s %-16s %s\n",$1,$2,$3,$6,$7,country; fflush()}; ****** example 2 example for DNS query log analysis awk '/queries/ {gsub(/queries.*client /,""); gsub(/#[0-9]+/,""); gsub(/: query:.*/,""); geoip="null"; "mygeoip.whob " $3 | getline geoip; close("mygeoip.whob " $3); printf("%s %s %16s %s %s\n", $1, $2, $3, geoip, $4); fflush()}' /tmp/somequeries ****** récap 1. needs to be set to undef, otherwise it will keep last value. 2. fflush() needs to be called a the end, because idk. 3. you call a command with a string "mygeoip " $7. 4. this will call mygeoip with argument $7. 5. you capture the output of that command with | getline . ***** use system result = system("ls") *** conditionals **** with patterns if (/regex/) { ... } else {...} **** gl if (condition) {} elif (condition) {statements>} else {} **** examples l'alias rip : tail -f /var/log/dovecot.log | awk '{if (match($0,/rip=10.10.10.19/)) next; else if (match($0,/Login:.*rip/)) print "external", $0 }' *** functions **** String funcs don't forget to use print, otherwise you won't see anything. ***** sub, gsub, gensub sub : 1 time. g[lobal]sub : global sub. gen[erate]sub : generate a new string instead of changing the original. syntax : [g]sub(regex, substitution, [string]) gensub(regex, substitution, mode, [string]) string is $0 by default. mode can be g or G (global), or a number indicating which match to replace. \1 matches first subexpression, \2 second etc. ***** match(string, regex, array) array[0] will contain whole match, if any array[n] will contain nth subgroup, if any return index of first occurence. attention sous mawk il n'y a pas de array on a simplement match(string,regex) ***** split(string, array, sep) fields are separated by sep. Put each field separatly in the array. Useful for eg. to split a field that contains multiple lines to an array of lines. ***** patsplit(string, array, fieldpat) fields are defined in fieldpat. Put each field separatly in the array. ***** sprintf(format,vars...) store formatted string to out out=sprintf(format,vars...) out=sprintf("it is %f outside", 39.2); *** user variables user variables need not be preceded by a $ *** accessing columns via a variable col=2 $col will select 2nd column. $(NF-3) will access 3rd to last column. *** when things go wrong/unexpected **** // and { on same line the pattern and the actions opening brace need to be on the same line symptoms : same line printed twice *** arrays **** print keys for (key in array) {print key} **** create an array of strings split("value1 value2 value3", ARRAY, " ") ARRAY will be initialized with values from the string passed as first argument, the last argument is the separator to split. *** unbuffered output use fflush(); in mawk, you can use -W interactive ** base64 Pour décoder un fichier en base64 on peut utiliser : base64 -di -d decode -i ignore garbage. En effet, la format MIME exige des séparations de ligne par CRLF que base64 -d ne parse pas. ** bash see ~/NOTES/TXT/bash.info ** bc scale=2 ychaouche#ychaouche-PC 09:59:25 ~ $ bc <<< "scale=2; 6/14" .42 ychaouche#ychaouche-PC 09:59:33 ~ $ ** beautifulsoup *** BeautifulSoup class **** __init__(self,markup...) markup is either a string or a file-like object **** find(self,) only return first match **** findAll(self,name=None,attrs={},text=None...) name = name of the tag attrs = any attribute **** findNext find after this tag (not in its children) ** bind *** ajouter une zone slave éditer le fichier named.conf.local et ajouter un enregistrement en spécifiant : - type : slave - masters : la liste des serveurs maitres términés par un ; - file : le fichier .db qui sera utilisé. exemple zone "radioalgerie.dz."{ type slave; masters {10.10.10.4;}; file "/etc/bind/slave/radioalgerie.dz.db"; }; *** ne pas écouter sur ipv6 par défaut. enlever donc les listen-on-v6 s'il y en a. ** binwalk -e[xtract] ** boxes pour justifier le text : -a [hv](horizontal/vertical)[jlcr](justify,left,center,right) Example : -ahlvc (horizontal/left, vertical center) pour choisir le design : -d pour lister les designs disponibles : -l pour ajouter un padding : -p (idem que -a pour horizontal, vertical etc. on ajoute t pour top, b pour bottom et -a pour all) Exemple : -pv4h2 ** bzr *** bzr move files after they're been moved bzr move --auto *** last revision -r last:1 *** show modified files bzr log -v -r *** change parent branch either edit the parent_location in : .bzr/branch/branch.conf (p) or run bzr reconfigure --unstacked-parent=path/to/new/parent/branch (you) ** catchsegv $ catchsegv program arguments quand le program crash, output : - le contenu des registres - un stack trace ** cg & vg search with cg like regular grep open nth result with vg n ** chmod ** command command -v / -V will give you path to the command, or specify if the command is a shell builtin ** cowsay cowsay / cowthink L'émotion avec -s(toned), -d(ead), -y(oung), -p(arano), -b(org), -g(reedy), -t(ired), -w(eird) l'apparence avec -f (-l pour lister toutes les apparences) ** cp *** copier les fichiers pointés par un symlink cp -L *** créer les répertoires intermédiaires cp --parents (ne fonctionne qu'avec un répertoire) ** cron *** every 5 minutes m h d dow dom */5 * * * * ** ctags / etags etags *.py. c'est tout. Sinon etags -o . Ensuite il suffit de déplacer le curseur vers un appel de fonction/méthod et de faire M-., ça emmene à la définition. Si ce n'est pas le bon endroit, on fait C-u M.- ** curl *** skip certificate -k *** follow redirects -L *** output to a file -o *** only http status (headers) (404/500/200) -I *** spoofing user agent --user-agent example : curl --user-agent "Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Firefox/91.0 Waterfox/91.4.2" *** continue old download -C - # - is part of the command, it means do your best. *** use a proxy -x *** stop if problem (404/500...) use -f[ail] *** do not print status information use -s[ilent] ** date *** textual date print what date is three months and one day from now : date --date='3 months 1 day' *** print date as YYYY-MM-DD format is given with + date --date yesterday +%Y-%m-%d *** date in seconds since epoch date +%s *** convert seconds since epoch to date ychaouche#ychaouche-PC 13:05:43 ~ $ date --date=@1605096302 Wed Nov 11 13:05:02 CET 2020 ychaouche#ychaouche-PC 13:05:48 ~ $ *** add durations to dates $ date -d "2022-05-29 10:00:00 +2 months -4 days + 11 hours - 29 minutes" Sat Jun 25 19:31:00 CET 2022 $ *** dateutils **** convert seconds to hh:mm:ss $ dateutils.dconv -f "%H:%M:%S" -i '%s' 830 00:13:50 **** difference between two time durations petit problème de formatage, je ne sais pas comment régler ça encore. ychaouche#ychaouche-PC 10:03:40 ~ $ dateutils.ddiff -f "%H:%M:%S" "01:50:00" "00:27:00" -1:-23:0 ychaouche#ychaouche-PC 10:03:47 ~ $ -i pour formatter la date en entrée 13:44:58 ~ -1- $ dateutils.ddiff -i "%M:%S" "26:41" "27:31" 50s 13:45:27 ~ -1- $ ** dbus voir qdbus et qdbusviewer ** dd When to use dd ? 1. When you need to copy part of a file, anywhere inside it (skip and count) 2. When you need to resume a copy that hasn't finished (skip) cp is sometimes 2.5 times faster than dd, source : https://www.reddit.com/r/linux4noobs/comments/6u6828/dd_vs_cp/dlqhdar/ ** di an alternative to df which displays info for mounted filesystems, optimized for real partitions and disks, not loopback and pseudo-filesystems. ** diff *** summary of differences -q : show only files that differ between two dirs ychaouche#ychaouche-PC 13:29:03 / $ diff -q /opt/libreoffice* Files /opt/libreoffice6.1/CREDITS.fodt and /opt/libreoffice7.0/CREDITS.fodt differ Common subdirectories: /opt/libreoffice6.1/help and /opt/libreoffice7.0/help Files /opt/libreoffice6.1/LICENSE and /opt/libreoffice7.0/LICENSE differ Only in /opt/libreoffice6.1: LICENSE.fodt Files /opt/libreoffice6.1/LICENSE.html and /opt/libreoffice7.0/LICENSE.html differ Common subdirectories: /opt/libreoffice6.1/presets and /opt/libreoffice7.0/presets Common subdirectories: /opt/libreoffice6.1/program and /opt/libreoffice7.0/program Common subdirectories: /opt/libreoffice6.1/readmes and /opt/libreoffice7.0/readmes Common subdirectories: /opt/libreoffice6.1/share and /opt/libreoffice7.0/share ychaouche#ychaouche-PC 13:29:05 / $ *** use -r on directories otherwise it won't recurse *** -c shows context it is useful to start w/ original file, then the modified file. - : removed from orig + : added to orig ! : changed This shows too much context of both files. Unified output is better. sample output : ychaouche#ychaouche-PC 12:00:43 ~/DOWNLOADS/APPS/VPN_Clients $ diff -c tda.ovpn.orig tda.ovpn *** tda.ovpn.orig 2022-05-17 16:12:15.806757623 +0100 --- tda.ovpn 2022-05-18 11:37:46.981400758 +0100 *************** *** 1,13 **** dev tun persist-tun persist-key - data-ciphers AES-256-GCM:AES-128-GCM:CHACHA20-POLY1305:AES-256-CBC - data-ciphers-fallback AES-256-CBC auth SHA256 tls-client client resolv-retry infinite ! remote 80.246.1.223 18223 udp4 verify-x509-name "radioalgerie.local" name auth-user-pass remote-cert-tls server --- 1,12 ---- dev tun persist-tun persist-key auth SHA256 + cipher AES-256-CBC tls-client client resolv-retry infinite ! remote 80.246.1.223 18223 udp verify-x509-name "radioalgerie.local" name auth-user-pass remote-cert-tls server ychaouche#ychaouche-PC 12:01:29 ~/DOWNLOADS/APPS/VPN_Clients $ *** -u unified (compressed) (preferred) context **** intro use orig before modified version - : deleted from original + : added to original **** sample output ychaouche#ychaouche-PC 12:31:41 ~/DOWNLOADS/APPS/VPN_Clients $ diff -u tda.ovpn.orig tda.ovpn --- tda.ovpn.orig 2022-05-17 16:12:15.806757623 +0100 +++ tda.ovpn 2022-05-18 11:37:46.981400758 +0100 @@ -1,13 +1,12 @@ dev tun persist-tun persist-key -data-ciphers AES-256-GCM:AES-128-GCM:CHACHA20-POLY1305:AES-256-CBC -data-ciphers-fallback AES-256-CBC auth SHA256 +cipher AES-256-CBC tls-client client resolv-retry infinite -remote 80.246.1.223 18223 udp4 +remote 80.246.1.223 18223 udp verify-x509-name "radioalgerie.local" name auth-user-pass remote-cert-tls server ychaouche#ychaouche-PC 12:31:46 ~/DOWNLOADS/APPS/VPN_Clients $ **** short output (-u0) ychaouche#ychaouche-PC 12:35:30 ~/DOWNLOADS/APPS/VPN_Clients $ diff -u0 tda.ovpn.orig tda.ovpn --- tda.ovpn.orig 2022-05-17 16:12:15.806757623 +0100 +++ tda.ovpn 2022-05-18 11:37:46.981400758 +0100 @@ -4,2 +3,0 @@ -data-ciphers AES-256-GCM:AES-128-GCM:CHACHA20-POLY1305:AES-256-CBC -data-ciphers-fallback AES-256-CBC @@ -6,0 +5 @@ +cipher AES-256-CBC @@ -10 +9 @@ -remote 80.246.1.223 18223 udp4 +remote 80.246.1.223 18223 udp ychaouche#ychaouche-PC 12:35:37 ~/DOWNLOADS/APPS/VPN_Clients $ or diff (normal output) ychaouche#ychaouche-PC 12:35:37 ~/DOWNLOADS/APPS/VPN_Clients $ diff tda.ovpn.orig tda.ovpn 4,5d3 < data-ciphers AES-256-GCM:AES-128-GCM:CHACHA20-POLY1305:AES-256-CBC < data-ciphers-fallback AES-256-CBC 6a5 > cipher AES-256-CBC 10c9 < remote 80.246.1.223 18223 udp4 --- > remote 80.246.1.223 18223 udp ychaouche#ychaouche-PC 12:36:59 ~/DOWNLOADS/APPS/VPN_Clients $ ** dig *** voir tous les enregistrements DNS dig ANY *** +short one line *** +search append domains from the search configuration of /etc/resolv.conf *** invoking dig @ *** if query takes too long probably timed out queries. use +qr to see the queries. ** disown enleve le processus du shell courant. il continuera à s'executer sous le même utilisateur, mais quand celui-ci se déconnectera, il continuera à s'executer. ça a plusieurs usages : 1. Ne plus être embêté par les messages 2. Si on se déconnecte, le processus continue de fonctionner 3. On immunise le process des signaux envoyés au/du shell parent ** djbdns package for dns server, cache, client and debugging tools http://cr.yp.to/djbdns.html It is used for millions of hosts around the web. Source : http://cr.yp.to/djbdns/blurb.html <<< November 2008 .com update: There are 78.1 million .com names on the Internet. At least 4.6 million .com names are hosted by servers that, according to the fpdns fingerprint tool, run djbdns. The only software packages used for more names are BIND (20.6 million), MyDNS (17.8 million), and PowerDNS (6.6 million). >>> ** dmesg dmesg -T shows timestamps in human readable format. ** dpkg / dpkg-query *** by function **** rechercher ***** rechercher un paquet installé par motif dpkg/dpkg-query -l *pattern* liste les paquets dont le nom ressemblent à pattern ***** quel paquet fournit cette commande / ce fichier dpkg/dpkg-query -S *pattern* **** lister ***** afficher tous les paquets installés dpkg-query -l dpkg -l ***** lister tous les fichiers installés par un paquet dpkg -L packagename dpkg-query -L packagename ***** lister les fichiers d'un paquet .deb dpkg -c ***** afficher l'état de tous les paquets matchant un pattern dpkg -l dpkg-query -l **** vérifications ***** how to inspect a .deb package? les paquets sont des archives au format ar, utiliser la commande ar pour extraire le fichier data.tar.xz comme ceci : ar xvf data.tar.xz puis inspecter à l'aide de tar vJf l'archive data.tar.xz AUTRE METHODE On peu extraire directement vers un réperoire avec ar pvf data.tar.xz | tar Jvx -C en effet, p[rint] va rediriger la sortie de ar vers la sortie de standard, de telle sorte à ce que tar puisse lire directement. par exemple : ar fp libssl-dev_1.1.0l-1~deb9u4_amd64.deb data.tar.xz | tar Jvx -C libssl-dev_1.1/ ***** est-ce que ce paquet est installé dpkg-query -W : show any (installed) package matching pattern dpkg / dpkg-query -s : show description of a specific package ***** y a-t-il des paquets qui utilisent des fichiers dans ce dossier ? dpkg/dpkg-query -S /path/vers/dossier exemple: root#ychaouche-PC 13:43:19 /usr/lib/debug/usr/lib # dpkg -S /usr/lib/debug/ kate-dbg, kdelibs5-dbg, kde-baseapps-dbg, konsole-dbg, kde-runtime-dbg, libqt4-dbg:amd64, libgmime-2.6-0-dbg, libc6-dbg:amd64: /usr/lib/debug root#ychaouche-PC 13:44:59 /usr/lib/debug/usr/lib # ***** à quel paquet appartient ce fichier ? dpkg/dpkg-query -S /path/vers/fichier ***** vérifier l'intégrité des paquets ****** commande et sortie dpkg -V en tant root (sans argument) explication de la sortie : 1. seulement les fichiers pour lesquels un test a échoué sont affichés 2. une série de 9 caractères sont affichés, un pour chaque test. 3. ? = le test n'a pas pu être fait. . = test ok [:alnum:] = code d'erreur ****** utilité si la machine est déjà compromise, il ne sert à rien de lancer cette commande. ce qu'il faudrait c'est que les hashs soient comparés avec un autre système réputé sain. **** cancel changes to conf files dpkg --force-confnew **** forcer la suppression d'un paquet dpkg --force-all --remove [1] [1] https://wiki.debian.org/DebianPackageManagement#line-271 *** by option **** dpkg-query -S[earch] search for filename in installed packages **** dpkg-query -s[tatus] report status for a specified package (installed or not) **** dpkg-query -l[ist packages] list packages la première colonne contient deux drapeaux. Le premier drapeau est l'action désiré pour ce paquet : i Install r Remove u unknown Le deuxième drapeau est l'état du paquet i Installed c config-files n not installed **** dpkg-query -L[ist files] list files of a package **** dpkg-query -[sho]W identique à -l sauf qu'elle permet de spécifier le format de la sortie. ** dpkg-query voir * by function ** working with packages ** debian ** dpkg ** ed voir * ed (bookmark-jump "linux::ed") ** emacs voir emacs.info ** expand transform tabs to spaces see also ** unexpand ** expect *** shebang #!/usr/bin/expect *** how to run a command ? spawn command *** how to capture output ? expect 'pattern' {action} *** how to send input ? send "input\r" *** how to keep terminal open after last command ? interact *** don't use simple quotes they don't delimit strings *** how to use a remote bash variable? quote the double quotes and quote the $, like this : \"\$REGX_IP\" ** ext4magic *** listing recovarable files # ext4magic /dev/sdXY -a "$(date -d "-2hours" +%s)" -f deleted/folders/root -j /some/safe/path/sdXY.journal -l example: ext4magic /dev/sda1 -Lx -f root/ > /tmp/files list all recoverable files in the last 24h in the /root/ subdir (note that the argument root/ is given w/o first slash) *** options -a[fter] time in seconds since epoch default is 24h -f[older] only scan for files in this folder -j[ournal] use the backup of the journal. Only useful if you made a backup (with debugfs) before a reboot. otherwise it reads the current journal by default. -l[ist] the deleted files -d[estination] -r[ecoverable] 100% recoverable only -R[ecoverable] partially recoverable files too -m[ulti-stage] recover all deleted files in a multi-stage operation - *** notes couldn't recover test.sh file ** extundelete extundelete /dev/sda1 --restore-file /root/test.sh ** fail2ban *** how to get the config of a jail ? fail2ban-client get both and support tab completion fail2ban-client get or you can do (nasty) fail2ban-client -d[ump] | grep *** how to get dbinfo ? fail2ban-client get dbfile *** how to get the list of banned IPs ? 1. grep Ban /var/log/fail2ban.log 2. iptables -L INPUT -v -n 3. fail2ban-client status *** how to unban ? fail2ban-client set unbanip <192.168.211.76> *** how to test a regex fail2ban-regex [-v[erbose]] both and can be strings or files for example : root@messagerie-principale[10.10.10.19] ~ # fail2ban-regex -v /var/log/mail.warn /etc/fail2ban/filter.d/postfix-sasl.conf Running tests ============= Use failregex file : /etc/fail2ban/filter.d/postfix-sasl.conf Use log file : /var/log/mail.warn Results ======= Failregex: 23 total |- #) [# of hits] regular expression | 1) [23] ^\s*(<[^.]+\.[^.]+>)?\s*(?:\S+ )?(?:kernel: \[ *\d+\.\d+\] )?(?:@vserver_\S+ )?(?:(?:\[\d+\])?:\s+[\[\(]?postfix/smtpd(?:\(\S+\))?[\]\)]?:?|[\[\(]?postfix/smtpd(?:\(\S+\))?[\]\)]?:?(?:\[\d+\])?:?)?\s(?:\[ID \d+ \S+\])?\s*warning: [-._\w]+\[\]: SASL ((?i)LOGIN|PLAIN|(?:CRAM|DIGEST)-MD5) authentication failed(:[ A-Za-z0-9+/:]*={0,2})?\s*$ | 172.16.10.53 Sun Nov 28 07:23:44 2021 | 103.167.84.118 Sun Nov 28 08:06:19 2021 | 136.144.41.223 Sun Nov 28 13:50:58 2021 | 136.144.41.223 Sun Nov 28 13:51:04 2021 | 136.144.41.223 Sun Nov 28 13:51:15 2021 | 136.144.41.223 Sun Nov 28 13:51:25 2021 | 136.144.41.223 Sun Nov 28 13:51:36 2021 | 136.144.41.223 Sun Nov 28 13:51:39 2021 | 136.144.41.223 Sun Nov 28 13:51:45 2021 | 136.144.41.223 Sun Nov 28 13:51:56 2021 | 136.144.41.223 Sun Nov 28 13:52:06 2021 | 136.144.41.223 Sun Nov 28 13:52:17 2021 | 136.144.41.223 Sun Nov 28 13:52:20 2021 | 109.237.103.19 Sun Nov 28 14:09:23 2021 | 109.237.103.19 Sun Nov 28 14:09:32 2021 | 109.237.103.19 Sun Nov 28 14:09:47 2021 | 109.237.103.19 Sun Nov 28 14:10:02 2021 | 109.237.103.19 Sun Nov 28 14:10:08 2021 | 109.237.103.19 Sun Nov 28 14:10:18 2021 | 109.237.103.19 Sun Nov 28 14:10:32 2021 | 109.237.103.19 Sun Nov 28 14:10:46 2021 | 109.237.103.19 Sun Nov 28 14:10:53 2021 | 109.237.103.19 Sun Nov 28 14:11:04 2021 `- Ignoreregex: 0 total [...] root@messagerie-principale[10.10.10.19] ~ # *** simulate a fail2ban run use fail2ban-regex with desired logfile and filter, see (bookmark-jump "fail2ban::fail2ban-regex") exemple: $ fail2ban-regex -v /var/log/mail.warn /etc/fail2ban/filter.d/postfix-sasl.conf ** fdisk menu-driven interface to work on disks, partitions ** find see ~/.bash_lib/help/find ** figlet La commande figlist donne toutes les polices supportés. Utilisez une police particulière avec l'option -f exemple : figlet -f whimsy "le purgatoire" utilisez l'option -w width pour avoir tout sur une ligne (exemple -w 120) exemple ychaouche#ychaouche-PC 17:35:56 ~ $ figlet -f weird -w 120 "le purgatoire 1.0" _ __ / / / /| / | ( ___ ___ ___ ___ ___ (___ ___ ___ ___ ( | ( | | |___) | )| )| )| )| )| | )| | )|___) | ) | ) | |__ |__/ |__/ | |__/ |__/||__ |__/ | | |__ _|/ |__/ | __/ - ychaouche#ychaouche-PC 17:35:59 ~ $ ** fold/fmt fmt is superior to fold when joining shorter lines. fold -s is superior to fold when you need to have short lines (bullets) you can use fill in emacs : M-q : fill-paragraphe ruler-mode : you know where you are auto-fill-mode : fill-as-you-type set-fill-column : instead of 80 ** fuser *** list processes using a file/dir/mountpoint use fuser -m[ount]v[erbose] the verbose option will display a ps like result root@messagerie-prep[10.10.10.20] ~ # fuser -m[ount]v[erbose] /var USER PID ACCESS COMMAND /var: root kernel mount /var root 718 ..c.. cron daemon 719 ..c.. atd clamav 723 F.c.. freshclam root 745 F.... dovecot root 794 F.... rsyslogd root 863 F.... log root 891 F.... apache2 postfix 1178 F.... opendkim mysql 1251 F.c.. mysqld root 1293 F.... fail2ban-server www-data 1312 F.... apache2 www-data 1313 F.... apache2 www-data 1314 F.... apache2 www-data 1315 F.... apache2 www-data 1316 F.... apache2 root 1584 F.c.. master postfix 1585 .rc.. pickup postfix 1586 ..c.. qmgr amavis 1588 F...m /usr/sbin/amavi postfix 1603 Frc.. tlsmgr amavis 1604 F.c.m /usr/sbin/amavi amavis 1605 F...m /usr/sbin/amavi www-data 1696 F.... apache2 dovecot 2176 F.... auth postfix 2181 Frc.m smtpd postfix 2182 ..c.. proxymap root@messagerie-prep[10.10.10.20] ~ # *** kill processes -k[ill] ** git *** clone Copies the whole data through the history of the project, not just the working copy. It is an exact copy (a clone) of the remote repo. *** getting only the working tree (checkout) **** archive doesn't work w/ github because command isn't allowed in their git server [1] git archive --remote --format tar git archive -0 for uncompressed output [2] git archive HEAD (tar format by default) for example: 16:06:53 ~/DOWNLOADS/TOOLS -1- $ git archive --remote=git://github.com/roma-glushko/tango.git HEAD fatal: unable to connect to github.com: github.com[0: 140.82.121.4]: errno=Connection timed out 16:10:57 ~/DOWNLOADS/TOOLS -1- $ [1] https://stackoverflow.com/questions/2866358/git-checkout-only-files-without-repository#comment47982597_2867314 [2] https://stackoverflow.com/questions/160608/do-a-git-export-like-svn-export#comment16482290_160608 **** clone --depth 1 **** git-export third party script ** grep voir /home/ychaouche/.bash_lib/help/grep:1 ** grep-dctrl *** gl invocation grep-dctrl