Because of [Archive] PragmaticProgrammers on Twitter: “Helpful Unix trick: use script to log your session. …” / Twitter:
- Linux:
- Windows
–jeroen
Posted by jpluimers on 2023/01/26
Because of [Archive] PragmaticProgrammers on Twitter: “Helpful Unix trick: use script to log your session. …” / Twitter:
–jeroen
Posted in *nix, *nix-tools, ash/dash, bash, bash, Batch-Files, Development, Power User, Scripting, Software Development | Leave a Comment »
Posted by jpluimers on 2022/12/28
Years ago, I wrote Getting your public IP address from the command-line. All methods were http based, so were very easy to execute using cURL.
But then in autumn 2021, Chris Bensen wrote this cool little blog-post [Wayback/Archive] Chris Bensen: How do I find my router’s public IP Address from the command line?:
dig -4 TXT +short o-o.myaddr.l.google.com @ns1.google.com
At first sight, I thought it was uncool, as the command was quite long and there was no explanation of the dig command trick.
But then, knowing that dig is a DNS client, it occurred to me: this perfectly works when http and https are disabled by your firewall, but the DNS protocol works and gives the correct result:
# dig -4 TXT +short o-o.myaddr.l.google.com @ns1.google.com "80.100.143.119"
This added the below commands and aliases to my tool chest for *nix based environments like Linux and MacOS (not sure yet about Windows yet :), but that still doesn’t explain why it worked. So I did some digging…
dig -4 TXT +short o-o.myaddr.l.google.com @ns1.google.com
dig -4 TXT +short o-o.myaddr.l.google.com @ns1.google.com | xargs
alias "whatismyipv4_dns=dig -4 TXT +short o-o.myaddr.l.google.com @ns1.google.com | xargs"
dig -6 TXT +short o-o.myaddr.l.google.com @ns1.google.com
dig -6 TXT +short o-o.myaddr.l.google.com @ns1.google.com | xargs
alias "whatismyipv6_dns=dig -6 TXT +short o-o.myaddr.l.google.com @ns1.google.com | xargs"
Let’s stick to dig and IPv4 as that not having IPv6 (regrettably still) is the most common situation today:
# dig -4 TXT +short o-o.myaddr.l.google.com @ns1.google.com "80.100.143.119"
What it does is request the DNS TXT record of o-o.myaddr.l.google.com from the Google DNS server ns1.google.com and returns the WAN IPv4 address used in the DNS request, which is for instance explained in [Wayback/Archive] What is the mechanics behind “dig TXT o-o.myaddr.l.google.com @ns1.google.com” : linuxadmin.
Since these are TXT records, dig will automatically double quote them, which xargs can remove (see below how and why):
# dig -4 TXT +short o-o.myaddr.l.google.com @ns1.google.com | xargs 80.100.143.119
The DNS query will fail when requesting the Google Public DNS servers 8.8.8.8 or 8.8.4.4:
# dig -4 TXT +short o-o.myaddr.l.google.com @8.8.8.8 "2a00:1450:4013:c1a::103" "edns0-client-subnet 80.101.239.0/24"
Or, with quotes removed (the -L 1 ensures that xargs performs the quote-pair removal action on each line):
# dig -4 TXT +short o-o.myaddr.l.google.com @8.8.8.8 | xargs -L 1 2a00:1450:4013:c1a::103 edns0-client-subnet 80.101.239.0/24
This request is both slower than requesting the ns1.google.com server and wrong.
The reason is that only ns1.google.com understands the special o-o.myaddr.l.google.com hostname which instructs it to return the IP address of the requesting dig DNS client.
That 8.8.8.8 returns a different IP address and an additional edns0-client-subnet with less accurate information is explained in an answer to [Wayback/Archive] linux – Getting the WAN IP: difference between HTTP and DNS – Stack Overflow by [Wayback/Archive] argaz referring to this cool post: [Wayback/Archive] Which CDNs support edns-client-subnet? – CDN Planet.
ns1.google.com: any DNS server serving the google.com domainSince o-o.myaddr.l.google.com is part of the google.com domain, the above works for any DNS server serving the google.com domain (more on that domain: [Wayback/Archive] General DNS overview | Google Cloud).
Getting the list of DNS servers is similar to getting the list of MX servers which I explained in Getting the IP addresses of gmail MX servers, replacing MX record type (main exchange) with the NS record type (name server) and the gmail.com domain with the google.com domain:
# dig @8.8.8.8 +short NS google.com ns3.google.com. ns1.google.com. ns2.google.com. ns4.google.com.
The ns1.google.com DNS server is a special one of the NS servers: it is the start of authority server, which you can query using the SOA record type that also gives slightly more details for this server:
# dig @8.8.8.8 +short SOA google.com ns1.google.com. dns-admin.google.com. 410477869 900 900 1800 60
The difference between using NS and SOA records with dig are explained in the [Wayback] dns – How do I find the authoritative name-server for a domain name? – Stack Overflow answer by [Wayback/Archive] bortzmeyer who also explains how to help figuring out SOA and NS discrepancies (note to self: check out the check_soa tool originally by Michael Fuhr (I could not find recent content of him, so he might have passed away) of which source code is now at [Wayback/Archive] Net-DNS/check_soa at master · NLnetLabs/Net-DNS).
So this works splendid as well using ns4.google.com on my test system:
# dig -4 TXT +short o-o.myaddr.l.google.com @ns4.google.com | xargs 80.100.143.119
xargs removes outer quotes removal trick[Wayback/Archive] string – Shell script – remove first and last quote (“) from a variable – Stack Overflow (thanks quite anonymous [Wayback/Archive] user1587520):
> echo '"quoted"' | xargs quoted
xargsusesechoas the default command if no command is provided and strips quotes from the input.
Some notes are in [Wayback/Archive] How to get public IP address from Linux shell, but note the telnet trick now fails as myip.gelma.net is gone (latest live version was archived in the Wayback Machine in august 2019).
whatismyipv4='curl ipv4.whatismyip.akamai.com && echo' It’s a quite a bit shorter than the dig construct in your post (;”–jeroen
Posted in *nix, *nix-tools, Apple, bash, bash, Batch-Files, Communications Development, Development, DNS, Internet protocol suite, Linux, Mac, Mac OS X / OS X / MacOS, Power User, Scripting, Software Development, TCP | Leave a Comment »
Posted by jpluimers on 2022/08/16
A while back Kristian Köhntopp (isotopp) wrote a blog post after quite a Twitter argument where he poses against using git empty commits. I’m with Kris: don’t use them for anything, especially not for kicking off your CI/CD.
Basically his blog post is all about avoiding to think you have a golden hammer, and avoid falling for the Law of the instrument – Wikipedia.
Originally, Abraham Maslow said in 1966:
“I suppose it is tempting, if the only tool you have is a hammer, to treat everything as if it were a nail.”
For me this has all to do with preventing technical debt: find the right tool to kick your CI/CD pipeline after part of that chain somehow malfunctioned is way better than polluting the commit history with empty commits.
His blog post: [Wayback/Archive.is] Empty commits and other wrong tools for the job | Die wunderbare Welt von Isotopp
The most important bit in it:
And since we are talking about CI/CD pipelines: Don’t YAML them. Don’t JSON them. Don’t XML them.
…
Programming in any of these three is wrong use of tooling, and you should not do it.
- YAML, JSON and XML are for declarative things.
- Python, Go and Rust are for procedural things.
- Bash is for interactive use only.
Use the proper tooling for the job. Be an engineer.
This very much reminds me of an Entwickler Konferenz keynote a long time ago, where Neal Ford made the point that most software engineers act very much unlike what is expected from traditional engineering way of operating where the engineer is both responsible and liable for his actions.
The start of the Twitter thread: [Archive.is] Kristian Köhntopp on Twitter: “A lot of people right now that git is an API and triggering CI/CD pipelines with empty commits replaces the equivalent of a Kubernetes controller for their fragile pile of bash in git triggers. This is broken and begets more brokenness. Evidence:… “
The tweet that started the subtweet: [Archive.is] Florian Haas on Twitter: “(For anyone wondering, what’s nice about this one is it works in any CI. So you don’t have to remember how to manually kick off a GitLab CI pipeline or GitHub Action or Zuul job, you just push an empty commit and off you go.)”
Other relevant tweets:
This solution still has one drawback. Gitlab requires a project specific token. If every developer uses the same token, its validity is bound to the project and not the individual contributor. While Gitlab allows users to create personal access tokens, you cannot require such a token to trigger a pipeline.
Yes, you want to avoid shell too (anything like for instance sh, ash, dash, bash or zsh), but you have to know it (and understand why to avoid it) as often it is the only interactive way to access systems from the console.
And of course Kris also wrote a big document on that too, which is available as full PDF (Wayback), full HTML (Wayback) and chaptered HTML Die UNIX Shell /bin/sh.
But more importantly, Kris wrote [Wayback/Archive.is] Using Python to bash | Die wunderbare Welt von Isotopp which is about using Python to do things you might be tempted to do in the shell. It quotes
Shell is a thing you want to understand and then not use, because you learned to understand it.
which is from the German post in thread [Wayback/Archive.is] Bashprogrammierung, wo gehts am besten los which quotes Kris’ 1998 message:
From kris Tue Sep 1 11:26:12 1998 From: kris Newsgroups: de.comp.os.unix.misc Subject: Re: Shell-Frage, find, xargs, kopieren von vielen Dateien References: <6seh24$q9a$2...@nz12.rz.uni-karlsruhe.de> From: kr...@koehntopp.de (Kristian Koehntopp) Alignment: chaotic/neutral X-Copyright: (C) Copyright 1987-1998 Kristian Koehntopp -- All rights reserved. MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Marc.Hab...@gmx.de (Marc Haber) writes: >mir ist das ganze Zeug mit der Shell, find, xargs und Konsorten noch >reichlich verschlüsselt. http://www.koehntopp.de/kris/artikel/unix/shellprogrammierung/ >xargs hin oder sollte ich besser ein Perlskript schreiben? Verwende Perl. Shell will man koennen, dann aber nicht verwenden. Kristian
–jeroen
Posted in *nix, *nix-tools, ash/dash, ash/dash development, bash, bash, Conference Topics, Conferences, Continuous Integration, Development, DVCS - Distributed Version Control, Event, git, Power User, Scripting, sh, Sh Shell, Software Development, Source Code Management, Technical Debt | Leave a Comment »
Posted by jpluimers on 2022/05/12
Last year, I wrote about Filezilla: figuring out the cause of “Connection timed out after 20 seconds of inactivity” about sftp connection problems.
The solution there was to exclude part of bashrc with an if [Wayback] statement so bash would skip it during sftp, but not during ssh login:
[WayBack] linux – Use .bashrc without breaking sftp – Server Fault
- From answer 1 (thanks [WayBack] Mike):
Try doing this instead
if [ "$SSH_TTY" ] then source .bashc_real fi- From Answer 2 (thanks [WayBack] Insyte):
A good trick for testing the cleanliness of your login environment is to
sshin with a command, which simulates the same wayscp/sftpconnect. For example:ssh myhost /bin/truewill show you exactly whatscp/sftpsees when they connect.
That caused some scripts not to be run when switching user, for instance by doing sudo su -.
The reason for that was that I forgot to put enough research in part of Answer 2, so I quote a few bits more of it (highlights and code markup mine):
… it’s worth pointing out that you can accomplish this carefully selecting which startup files to put the verbose stuff in. From the
bashman page:When
bashis invoked as an interactive login shell, or as a non-interactive shell with the--loginoption, it first reads and executes commands from the file/etc/profile, if that file exists. After reading that file, it looks for~/.bash_profile,~/.bash_login, and~/.profile, in that order, and reads and executes commands from the first one that exists and is readable. The--noprofileoption may be used when the shell is started to inhibit this behavior.When an interactive shell that is not a login shell is started,
bashreads and executes commands from~/.bashrc, if that file exists. This may be inhibited by using the--norcoption. The--rcfilefile option will force bash to read and execute commands from file instead of~/.bashrc.The
sftp/scptools start an interactive non-login shell, so.bashrcwill be sourced.
For further reading, there is the underlying bash manual as a PDF file [Wayback] and html document tree [Wayback]. Note it is large (the PDF is 190 pages).
I find the easiest way to navigate around bash documentation through these links:
Basically, from the above answer there are [Archive.is] 4 types of shells (confirmed by these parts of the bash documentation: [Wayback] Section 6.1: Invoking-Bash and [Wayback] Section 6.2: Bash-Startup-Files):
And there are various means the shells can start (ssh, local console, …). The "$SSH_TTY" trick only checks interactive login via ssh, but fails to detect others.
So I did some digging for the correct information to log, which including the above are:
-hLocate and remember (hash) commands as they are looked up for execution. This option is enabled by default.-mJob control is enabled (see Job Control). All processes run in a separate process group. When a background job completes, the shell prints a line containing its exit status.-BThe shell will perform brace expansion (see Brace Expansion). This option is on by default.-HEnable ‘!’ style history substitution (see History Interaction). This option is on by default for interactive shells.
Note that in addition to this, there is the non-settable option i: The current shell is interactive (see the -i in section 6.1 below).
login_shellThe shell sets this option if it is started as a login shell (see Invoking Bash). The value may not be changed.
There are several single-character options that may be supplied at invocation which are not available with the
setbuiltin.
-iForce the shell to run interactively. Interactive shells are described in Interactive Shells.…
A login shell is one whose first character of argument zero is ‘-’, or one invoked with the –login option.
To determine within a startup script whether or not Bash is running interactively, test the value of the ‘-’ special parameter. It contains
iwhen the shell is interactive. For example:case "$-" in *i*) echo This shell is interactive ;; *) echo This shell is not interactive ;; esacAlternatively, startup scripts may examine the variable
PS1; it is unset in non-interactive shells, and set in interactive shells. Thus:if [ -z "$PS1" ]; then echo This shell is not interactive else echo This shell is interactive fi
After reading the above documentation links, I put the below code in the global .bashrc (which of course caused trouble with sftp, so I commented it out later):
echo "Option flags: '$-'" echo "PS1: '$PS1'" echo "shopt login_shell: '$(shopt login_shell)'" echo "Parameter zero: '$0'" [ "$SSH_TTY" ] ; echo "[ \"\$SSH_TTY\" ] outcome: $?"
And the output after these commands:
ssh user@host
Option flags: 'himBH' PS1: '\u@\h:\w> ' shopt login_shell: 'login_shell on' Parameter zero: '-bash' [ "$SSH_TTY" ] outcome: 0
Verdict: interactive, login
ssh user@host
followed by
sudo su -
Option flags: 'himBH' PS1: '\[\]\h:\w #\[\] ' shopt login_shell: 'login_shell on' Parameter zero: '-bash' [ "$SSH_TTY" ] outcome: 1
Verdict: interactive, login
ssh user@host
followed by
bash
Option flags: 'himBH' PS1: '\u@\h:\w> ' shopt login_shell: 'login_shell off' Parameter zero: 'bash' [ "$SSH_TTY" ] outcome: 0
Verdict: interactive, non-login
ssh user@host
followed by
sudo su -
then by
bash
Option flags: 'himBH' PS1: '\[\]\h:\w #\[\] ' shopt login_shell: 'login_shell off' Parameter zero: 'bash' [ "$SSH_TTY" ] outcome: 1
Verdict: interactive, non-login
ssh user@host /bin/true
Option flags: 'hBc' PS1: '' shopt login_shell: 'login_shell off' Parameter zero: 'bash' [ "$SSH_TTY" ] outcome: 1
Verdict: non-interactive, non-login
The final one is what for instance sftp will see. It excludes the non-interactive mark in the shopt option flags.
.bashrc fileSince the [Wayback] test for "$SSH_TTY" is inconsistent with the login being interactive, I modified the .bashrc section
if [ "$SSH_TTY" ] then source .bashc_real fi
to become
if [[ $- =~ i ]] then # only during interactive login shells source .bashc_real fi
I know the [[...]] over test shorthand [...] is a bashism, see [Wayback] if statement – Is double square brackets [[ ]] preferable over single square brackets [ ] in Bash? – Stack Overflow for why I like it.
I based the above changes not only on the mentioned StackOverflow post, but also doing some more Googling revealing these useful documentation and question/answer links:
[[ expression ]]
[[…]][[ expression ]]Return a status of
0or1depending on the evaluation of the conditional expression expression. Expressions are composed of the primaries described below in Bash Conditional Expressions. Word splitting and filename expansion are not performed on the words between the[[and]]; tilde expansion, parameter and variable expansion, arithmetic expansion, command substitution, process substitution, and quote removal are performed. Conditional operators such as ‘-f’ must be unquoted to be recognized as primaries.…
An additional binary operator, ‘
=~’, is available, with the same precedence as ‘==’ and ‘!=’. When it is used, the string to the right of the operator is considered a POSIX extended regular expression and matched accordingly (using the POSIXregcompandregexecinterfaces usually described inregex(3)). The return value is0if the string matches the pattern, and1otherwise. If the regular expression is syntactically incorrect, the conditional expression’s return value is2.
test or [...] (Bash Reference Manual)test exprEvaluate a conditional expression expr and return a status of
0(true) or1(false). Each operator and operand must be a separate argument. Expressions are composed of the primaries described below in Bash Conditional Expressions.testdoes not accept any options, nor does it accept and ignore an argument of--as signifying the end of options.When the
[form is used, the last argument to the command must be a].
$1,$2,$3, … are the positional parameters."$@"is an array-like construct of all positional parameters,{$1, $2, $3 ...}."$*"is the IFS expansion of all positional parameters,$1 $2 $3 ....$#is the number of positional parameters.$-current options set for the shell.$$pid of the current shell (not subshell).$_most recent parameter (or the abs path of the command to start the current shell immediately after startup).$IFSis the (input) field separator.$?is the most recent foreground pipeline exit status.$!is the PID of the most recent background command.$0is the name of the shell or shell script.Most of the above can be found under Special Parameters in the Bash Reference Manual. There are all the environment variables set by the shell.
For a comprehensive index, please see the Reference Manual Variable Index.
Briefly (see here for more details), with examples:
- interactive login shell: You log into a remote computer via, for example
ssh. Alternatively, you drop to a tty on your local machine (Ctrl+Alt+F1) and log in there.- interactive non-login shell: Open a new terminal.
- non-interactive non-login shell: Run a script. All scripts run in their own subshell and this shell is not interactive. It only opens to execute the script and closes immediately once the script is finished.
- non-interactive login shell: This is extremely rare, and you’re unlikey to encounter it. One way of launching one is
echo command | ssh server. Whensshis launched without a command (sosshinstead ofssh commandwhich will runcommandon the remote shell) it starts a login shell. If thestdinof thesshis not a tty, it starts a non-interactive shell. This is whyecho command | ssh serverwill launch a non-interactive login shell. You can also start one withbash -l -c command.If you want to play around with this, you can test for the various types of shell as follows:
- Is this shell interactive?Check the contents of the
$-variable. For interactive shells, it will includei:## Normal shell, just running a command in a terminal: interacive $ echo $- himBHs ## Non interactive shell $ bash -c 'echo $-' hBc- Is this a login shell?There is no portable way of checking this but, for bash, you can check if the
login_shelloption is set:## Normal shell, just running a command in a terminal: interacive $ shopt login_shell login_shell off ## Login shell; $ ssh localhost $ shopt login_shell login_shell onPutting all this together, here’s one of each possible type of shell:
## Interactive, non-login shell. Regular terminal $ echo $-; shopt login_shell himBHs login_shell off ## Interactive login shell $ bash -l $ echo $-; shopt login_shell himBHs login_shell on ## Non-interactive, non-login shell $ bash -c 'echo $-; shopt login_shell' hBc login_shell off ## Non-interactive login shell $ echo 'echo $-; shopt login_shell' | ssh localhost Pseudo-terminal will not be allocated because stdin is not a terminal. hBs login_shell on
A login shell is the first process that executes under your user ID when you log in for an interactive session. The login process tells the shell to behave as a login shell with a convention: passing argument 0, which is normally the name of the shell executable, with a
-character prepended (e.g.-bashwhereas it would normally bebash. Login shells typically read a file that does things like setting environment variables:/etc/profileand~/.profilefor the traditional Bourne shell,~/.bash_profileadditionally for bash†,/etc/zprofileand~/.zprofilefor zsh†,/etc/csh.loginand~/.loginfor csh, etc.When you log in on a text console, or through SSH, or with
su -, you get an interactive login shell. When you log in in graphical mode (on an X display manager), you don’t get a login shell, instead you get a session manager or a window manager.It’s rare to run a non-interactive login shell, but some X settings do that when you log in with a display manager, so as to arrange to read the profile files. Other settings (this depends on the distribution and on the display manager) read
/etc/profileand~/.profileexplicitly, or don’t read them. Another way to get a non-interactive login shell is to log in remotely with a command passed through standard input which is not a terminal, e.g.ssh example.com <my-script-which-is-stored-locally(as opposed tossh example.com my-script-which-is-on-the-remote-machine, which runs a non-interactive, non-login shell).When you start a shell in a terminal in an existing session (screen, X terminal, Emacs terminal buffer, a shell inside another, etc.), you get an interactive, non-login shell. That shell might read a shell configuration file (
~/.bashrcfor bash invoked asbash,/etc/zshrcand~/.zshrcfor zsh,/etc/csh.cshrcand~/.cshrcfor csh, the file indicated by theENVvariable for POSIX/XSI-compliant shells such as dash, ksh, and bash when invoked assh,$ENVif set and~/.mkshrcfor mksh, etc.).When a shell runs a script or a command passed on its command line, it’s a non-interactive, non-login shell. Such shells run all the time: it’s very common that when a program calls another program, it really runs a tiny script in a shell to invoke that other program. Some shells read a startup file in this case (bash runs the file indicated by the
BASH_ENVvariable, zsh runs/etc/zshenvand~/.zshenv), but this is risky: the shell can be invoked in all sorts of contexts, and there’s hardly anything you can do that might not break something.† I’m simplifying a little, see the manual for the gory details.
If you want to avoid the [[...]] bashishm, then read [Wayback] Bashism: How to make bash scripts work in dash – Greg’s Wiki.
–jeroen
Posted in *nix, *nix-tools, ash/dash, bash, bash, Communications Development, Conference Topics, Conferences, Development, Event, Internet protocol suite, Power User, Scripting, SFTP, Software Development, SSH, TCP | Leave a Comment »
Posted by jpluimers on 2022/05/11
I wanted to know which pattern provides [WayBack] etckeeper which is in the [WayBack] openSUSE Software package etckeeper.
It seems no built-in search query can do that, so I built one my own.
Since the result takes quite a while to produce, the output is a pattern.txt that you can manually search.
This is the command:
zypper search -t pattern | grep "|" | tail -n +2 | perl -pe 's/^.*? \| //' | perl -pe 's/ *\| .*$//' | xargs -I {} sh -c "zypper info -t pattern {}" > patterns.txt
The content is like this (the 2017 date shows I wrote this a long time ago):
Posted in *nix, *nix-tools, bash, bash, Development, etckeeper, Linux, Perl, Power User, Scripting, sed, Software Development | Leave a Comment »
Posted by jpluimers on 2022/04/13
I say to people: only use shell interactively, don’t write scripts. Never. Not one.
But Kris, they ask, why so radical?
Because of this:
is the literal English Google Translation of the German text
Ich sage den Leuten: benutzt Shell nur interaktiv, schreibt keine Scripte. Nie. Nicht eines.
Aber Kris, fragen sie, wieso so Radikal?
Deswegen:
then links to [Wayback/Archive] Jan Schaumann on Twitter: “TIL zgrep(1) is a shell script. BSD basically does “zcat | grep”, but GNU does “gzip -dc | sed”. How did I learn that? The fun way! CVE-2022-1271, arbitrary-file-write and code execution vulnerability in GNU zgrep / gzip. …”:
Posted in *nix, *nix-tools, Apple, ash/dash, ash/dash development, bash, bash, BSD, Development, Mac, Mac OS X / OS X / MacOS, Power User, Scripting, Software Development | Leave a Comment »
Posted by jpluimers on 2022/03/16
Jilles posted a small script to show offline/online status based on ping in [Archive.is] Jilles on Twitter: “#!/bin/bash HOST={1ST HOP HERE} while true;do p=$(ping -c1 $HOST) if [ $? -ne 0 ];then s=offline else s=online\ fi echo $(date +%F\ %T) $s – $(echo $p | sed -e ‘s/^PING.*— 1/1/g’) sleep 10 done”
#!/bin/bash HOST={1ST HOP HERE} while true;do p=$(ping -c1 $HOST) if [ $? -ne 0 ];then s=offline else s=online\ fi echo $(date +%F\ %T) $s - $(echo $p | sed -e 's/^PING.*--- 1/1/g') sleep 10 done
The reason was that his ISP had connection problems for the block of homes where Jilles lives.
–jeroen
Posted in *nix, *nix-tools, bash, bash, Development, grep, Power User, Scripting, sed, Software Development | Leave a Comment »
Posted by jpluimers on 2022/03/15
This is cool: [Wayback] Cryptosense Discovery:
Free tool that discovers security configuration errors in SSH and TLS servers and explains how to fix them. Supports STARTTLS and can also scan HTTPS, POP3, IMAP and SMTP servers.
It gives you a list of servers a target domain uses (for purposes like web, email, etc) that can have external encryption enabled, then allows you to test these.
The list by default has only servers within that target domain enabled, but you can optionally include other servers (for instance if a domain uses a third party for their SMTP handling).
Basically it is the web-counterpart of a tool like testssl.sh (which I have written about before).
Found while checking out how to test the MX security of a domain using [Wayback] testssl.sh as I forgot the syntax, which in retrospect is dead easy as per [Wayback] tls – How to use testssl.sh on an SMTP server? – Information Security Stack Exchange (thanks [Wayback] Z.T.!):
…
testssl.sh --mx <domain name>works fine.
testssl.sh -t smtp <ip>:25and
testssl.sh -t smtp <ip>:587also work fine.
Note that not specifying the port assumes port 443, despite specifying protocol
smtp. That doesn’t work.…
Also, you might try discovery.cryptosense.com which does the same thing only better
That website is made by the cool people at [Wayback] Cryptosense.
Both are a lot easier than the alternatives described in [Wayback] Blog · How to test SMTP servers using the command-line · Halon MTA: using nslookup and dig for determining the affected hosts, using nc or telnet for testing basic connectivity, using [Wayback/Archive.is] openssl s_client to test TLS, and [Wayback/Archive.is] smtpping for measuring throughput.
In addition to the above tools mentioned in the blog, I’ve also used
sendEmail(note case sensitivity),ehlo-size, andswaks.
This is what I tested:
We found these machines for
clientondersteuningplus.nl. Select those you would like to scan:
clientondersteuningplus.nl185.37.70.68localhost.clientondersteuningplus.nl127.0.0.1pop.clientondersteuningplus.nl5.157.84.75These machines are also used by
clientondersteuningplus.nl. They seem to be managed by a third party:…
–jeroen
Posted in *nix, *nix-tools, Awk, bash, bash, Communications Development, Development, DNS, Encryption, grep, HTTPS/TLS security, Internet, Internet protocol suite, Power User, Scripting, Security, SMTP, Software Development, SSH, ssh/sshd, TCP, testssl.sh, TLS | Leave a Comment »
Posted by jpluimers on 2022/03/03
Cool, I didn’t realise how readlink operated, but found out a bit more in the answers to [Wayback] symlink – How to get full path of original file of a soft symbolic link? – Unix & Linux Stack Exchange, thanks to [Wayback] daisy, [Wayback] Peter.O and [Wayback] Gilles ‘SO- stop being evil’:
- Try this line:
readlink -f `which command`If
commandis in your$PATHvariable , otherwise you need to specify the path you know.
-fwill return a path to a non-existent final target, so long as the intermediate link targets exist… Use-eto avoid this, ie.-ewill return null if the final target does not exist. – Peter.O- Under Linux,
readlinkreads the contents of a symlink, andreadlink -ffollows symlinks to symlinks to symlinks, etc., until it finds something that isn’t a symlink.
–jeroen
Posted in *nix, *nix-tools, ash/dash, bash, bash, Development, Power User, Scripting, Software Development | Leave a Comment »
Posted by jpluimers on 2022/02/24
IoT devices still often use the ‘Basic’ HTTP Authentication Scheme for authorisation, see [Wayback] RFC7617: The ‘Basic’ HTTP Authentication Scheme (RFC ) and [Wayback] RFC2617: HTTP Authentication: Basic and Digest Access Authentication (RFC ).
Often this authentication is used even over http instead of over https, for instance the Egardia/Woonveilig alarm devices I wrote about yesterday at Egardia/Woonveilig: some notes about logging on a local gateway to see more detailed information on the security system. This is contrary to guidance in:
This scheme is not considered to be a secure method of user authentication unless used in conjunction with some external secure system such as TLS (Transport Layer Security, [RFC5246]), as the user-id and password are passed over the network as cleartext.
"HTTP/1.0", includes the specification for a Basic Access Authentication scheme. This scheme is not considered to be a secure method of user authentication (unless used in conjunction with some external secure system such as SSL [5]), as the user name and password are passed over the network as cleartext.
Fiddling with those alarm devices, I wrote these two little bash functions (with a few notes) that work both on MacOS and in Linux:
# `base64 --decode` is platform neutral (as MacOS uses `-D` and Linux uses `-d`) # `$1` is the encoded username:password function decode_http_Basic_Authorization(){ echo $1 | base64 --decode echo } # `base64` without parameters encodes # `echo -n` does not output a new-line # `$1` is the username; `$2` is the password function encode_http_Basic_Authorization(){ echo $1:$2 | base64 }
The first decodes the <credentials> from a Authorization: Basic <credentials> header into a username:password clean text followed by a newline.
The second one encodes a pair of username and password parameters into such a <credentials> string.
They are based on these initial posts that were not cross platform or explanatory:
–jeroen
Posted in *nix, *nix-tools, Apple, Authentication, bash, bash, Communications Development, Development, HTTP, Internet protocol suite, Linux, Mac OS X / OS X / MacOS, Power User, Scripting, Security, Software Development, TCP, Web Development | Leave a Comment »