Various Snippets of Code – Cheatsheet (Work in progress)

Snippets of Code

There are times you don’t remember a command syntax … here are the memory hooks. Work in progress.

AT commands:

ATI - show info
AT+CFUN=0 switch off mobile broadband modem radio.
AT+CFUN=1 switch on radio of a mobile broadband modem.
AT+CFUN=1,1 - fully reset a mobile broadband modem radio.
AT+CNUM - own number
AT+CLAC - list of AT commands

More: http://forensicswiki.org/wiki/AT_Commands

AWK

Some tutorials and examples:

DATE

show the date of the day that lies 8 days in the future

date -d "+8days"

or next week in UTC

date -d "next week" -u

Show the current date in Unix epochs

date +%s?

Show the day’s date at 2pm, in Unix epochs, that lies eight days in future

date -d "+8days 14:00" +%s

DRUSH (Drupal shell)

  • Update Drupal
drush upc -y && drush updb -y
  • Remove database entries for no longer present modules
drush sql-query "DELETE from system where name = 'image_gallery' AND type = 'module';"

FIND

  • list files with suffix .txt, with their file data modified within the last 24 hours.
find . -name "*.txt" -mtime -1
  • list files with suffix .txt, with their file status modified within the last 24 hours.
find . -name "*.txt" -ctime -1
  • list files with suffix .txt, that have been accessed within 24 hours (1*24)
find . -name "*.txt" -atime -1

LETSENCRYPT

LETSENCRYPT - create (beta) certificates
(certbot-auto)

./letsencrypt-auto --agree-dev-preview --server https://acme-v01.api.letsencrypt.org/directory auth
  • Automatically configure Apache and Nginx:

letsencrypt run

  • Simply create new certificate:
letsencrypt -d example.com auth
  • Renewing certificate
letsencrypt renew --cert-path example-cert.pem
  • Revoke certificate
letsencrypt revoke
  • Revoke certificate(s) with a particular key.
letsencrypt revoke --cert-path example-cert.pem
letsencrypt revoke --key-path example-key.pem
  • a small variation creating only the domain certs you list (domain list in ~user/lets-encrypt-domains)
./letsencrypt-auto --agree-dev-preview --server https://acme-v01.api.letsencrypt.org/directory `cat ~user/lets-encrypt-domains | sed 's/^/-d /' | tr "\n" " "` auth
  • for nginx use
cat cert.pem chain.pem >> chained-cert.pem
  • Expand a LE-Cert with additional alt names:
certbot-auto certonly --webroot --agree-tos -w /var/www/ \
--expand -d example.com,www.example.com,click.example.com

MySQL/MariaDB

  • Specified key was too long; max key length is 767 bytes

mysql -u USERNAME -p

use DATABASENAME;

 

set global innodb_large_prefix=on;

set global innodb_file_format=Barracuda;

set global innodb_file_per_table=true;

Source: https://stackoverflow.com/questions/10873870/mysql-error-1071-specified-key-was-too-long-max-key-length-is-1000-bytes-in-s

OpenSSL

  • remote Certificate checking:
openssl s_client -showcerts -connect www.domain.com:443

SYMPA (Mailing list service)

  • Look for invalid entries in your clear text database sympa should import:
awk -F' ' '{print $1,$2}' sympa-imported.txt | grep -E -v "\b[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z0-9.-]+\b"
  • Converting newer OpenSSL Keyfiles for use with MariaDB, that expects the old format from OpenSSL 1.0:
    openssl rsa -in "original-key.pem" -out "mysql-key.pem"

Source: https://www.blog.happytec.at/index.php?mode=view&id=304

rsync

  • Clone a running linux system with rsync:
    Source: https://www.ostechnix.com/backup-entire-linux-system-using-rsync/

    sudo rsync -aAXv / --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"} /mnt
  • Variation – Boot target system with grml or similar, set a root password and start ssh, then…
    sudo rsync -aAXv / --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"} root@secondsystem.my.doma.in:/mnt/

TFTP (dnsmasq)

/etc/init.d/network-manager stop; ip link set link up dev eth0 && ip a a 192.168.0.66/24 dev eth0 && killall -9 dnsmasq; dnsmasq -k --enable-tftp --tftp-root=/var/tftp/
  • For TFTP-Flashing TP-Link TL-WR842NDv1 (filename: wr842ndv1_tp_recovery.bin)
    If flashing is way to slow (takes minutes instead of a couple of seconds, block size negotiation may have failed), see –tftp-no-blocksize.
/etc/init.d/network-manager stop; ip link set link up dev eth0 && ip a a 192.168.1.66/24 dev eth0 && killall -9 dnsmasq; dnsmasq -k --enable-tftp --tftp-root=/var/tftp/ --tftp-no-blocksize

TOUCH

  • set the file’s (test.txt) date to be yesterday’s date
touch -d `date -d "1 day ago" '+%Y-%m-%d'` test.txt

XMLLINT

xmllint --noout --valid abc.xml

VARIOUS

related to UUID

  • Alternative to uuidgen command:
cat /proc/sys/kernel/random/uuid
  • setting UUID on device sdx1
tune2fs -U  /dev/sdx1

simple USB reset:

echo 0 > /sys/bus/usb/devices/usb1/authorized
echo 1 > /sys/bus/usb/devices/usb1/authorized

IPv6 “Rosetta Stone”

IPv6 cmd line tool and syntax of various OS compared: https://wikispaces.psu.edu/display/ipv6/IPv6+Rosetta+Stone

Detecting hidden WIFIs on Linux

https://cybersecuritylabs.wordpress.com/2014/02/25/uncovering-hidden-ssids/

Monitor:

airmon-ng start wlan0
airodump-ng mon0

Monitor specific BSSID and Channel:

airodump-ng -c <CHANNEL #> –bssid <BSSID> mon0

Deauthenticate in order to view Reauth with Wireshark:

aireplay-ng -0 30 -a <AP MAC/BSSID> -c <STATION MAC> mon0

(-0 = deauth; 30 = number of deauth tries;)

Wireshark filter for monitoring deauth packets only:

wlan.fc.type_subtype == 0x0c

Notifications and bots

  1. Telegram

/usr/bin/curl –silent -s -X POST “https://api.telegram.org/bot<BOT-ID&gt;:<BOT-SECRET>/sendMessage” -d chat_id=<CHAT-ID> -d text=”Action took place at `/bin/date`” > /dev/null

Source: https://forum.netcup.de/sonstiges/smalltalk/p124046-das-l%C3%A4ngste-thema/#post124046

2. SMTPS Notification with curl

 

#!/bin/bash

cat head.txt > /tmp/message.txt

echo “Whatever…” >> /tmp/message.txt

cat tail.txt >> /tmp/message.txt

curl url ‘smtps://smtp.mailbox.org:465/’ sslreqd mailfrom ‘mail@domain.tld’ mailrcpt ‘mail@domain.tld’ uploadfile /tmp/message.txt user ‘mail@domain.tld:<password>’

 

Source: https://forum.netcup.de/sonstiges/smalltalk/p124045-das-l%C3%A4ngste-thema/#post124045

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s