Tuesday, May 4, 2021

CLI Ways to Transfer file Part I

 CLI options:

file.io

Easy to use API

Try it out:

$ curl -F "file=@test.txt" https://file.io
{"success":true,"key":"2ojE41","link":"https://file.io/2ojE41","expiry":"14 days"}
$ curl https://file.io/2ojE41
This is a test
$ curl https://file.io/2ojE41
{"success":false,"error":404,"message":"Not Found"}

Or set an expiration:

$ curl -F "file=@test.txt" https://file.io/?expires=1w
{"success":true,"key":"aQbnDJ","link":"https://file.io/aQbnDJ","expiry":"7 days"}
$ sleep 604801
$ curl https://file.io/aQbnDJ
{"success":false,"error":404,"message":"Not Found"}

The query param expires must be a positive integer which, by default, represents the number of days until the file will be deleted (defaults to 14 days). If you follow it with w, it will be the number of weeks. m for months and y for years.

You can also send direct text to file.io:

$ curl --data "text=this is a secret pw" https://file.io
{"success":true,"key":"pgiPc2","link":"https://file.io/pgiPc2","expiry":"14 days"}
$ curl https://file.io/pgiPc2
this is a secret pw
$ curl https://file.io/pgiPc2
{"success":false,"error":404,"message":"Not Found"}


transfer.sh

Sample use cases

How to upload

# Uploading is easy using curl $ curl --upload-file ./hello.txt https://transfer.sh/hello.txt https://transfer.sh/66nb8/hello.txt $ curl -H "Max-Downloads: 1" -H "Max-Days: 5" --upload-file ./hello.txt https://transfer.sh/hello.txt https://transfer.sh/66nb8/hello.txt # Download the file $ curl https://transfer.sh/66nb8/hello.txt -o hello.txt

Add shell function to .bashrc or .zshrc

# Add this to .bashrc or .zshrc or its equivalent transfer(){ if [ $# -eq 0 ];then echo "No arguments specified.\nUsage:\n transfer <file|directory>\n ... | transfer <file_name>">&2;return 1;fi;if tty -s;then file="$1";file_name=$(basename "$file");if [ ! -e "$file" ];then echo "$file: No such file or directory">&2;return 1;fi;if [ -d "$file" ];then file_name="$file_name.zip" ,;(cd "$file"&&zip -r -q - .)|curl --progress-bar --upload-file "-" "https://transfer.sh/$file_name"|tee /dev/null,;else cat "$file"|curl --progress-bar --upload-file "-" "https://transfer.sh/$file_name"|tee /dev/null;fi;else file_name=$1;curl --progress-bar --upload-file "-" "https://transfer.sh/$file_name"|tee /dev/null;fi;} # Now you can use transfer function $ transfer hello.txt

More examples

Upload multiple files at once

$ curl -i -F filedata=@/tmp/hello.txt -F filedata=@/tmp/hello2.txt https://transfer.sh/ # Combining downloads as zip or tar archive $ curl https://transfer.sh/(15HKz/hello.txt,15HKz/hello.txt).tar.gz $ curl https://transfer.sh/(15HKz/hello.txt,15HKz/hello.txt).zip

Encrypt your files with gpg before the transfer

# Encrypt files with password using gpg $ cat /tmp/hello.txt|gpg -ac -o-|curl -X PUT --upload-file "-" https://transfer.sh/test.txt # Download and decrypt $ curl https://transfer.sh/1lDau/test.txt|gpg -o- > /tmp/hello.txt

Scan for malware

# Scan for malware or viruses using Clamav $ wget http://www.eicar.org/download/eicar.com $ curl -X PUT --upload-file ./eicar.com https://transfer.sh/eicar.com/scan # Upload malware to VirusTotal, get a permalink in return $ curl -X PUT --upload-file nhgbhhj https://transfer.sh/test.txt/virustotal

Backup mysql database, encrypt and transfer

# Backup, encrypt and transfer $ mysqldump --all-databases|gzip|gpg -ac -o-|curl -X PUT --upload-file "-" https://transfer.sh/test.txt

Send email with transfer link (uses shell function)

# Transfer and send email with link (uses shell function) $ transfer /tmp/hello.txt | mail -s "Hello World" user@yourmaildomain.com

Using Keybase.io

# Import keys from keybase $ keybase track [them] # Encrypt for recipient(s) $ cat somebackupfile.tar.gz | keybase encrypt [them] | curl --upload-file '-' https://transfer.sh/test.txt # Decrypt $ curl https://transfer.sh/sqUFi/test.md |keybase decrypt

wget uploads also supported

# wget $ wget --method PUT --body-file=/tmp/file.tar https://transfer.sh/file.tar -O - -nv

Transfer pound logs

# grep syslog for pound and transfer $ cat /var/log/syslog|grep pound|curl --upload-file - https://transfer.sh/pound.log

Upload a file using Powershell

# Upload using Powershell PS H:\> invoke-webrequest -method put -infile .\file.txt https://transfer.sh/file.txt

Upload a file using HTTPie

# HTTPie $ http https://transfer.sh/ -vv < /tmp/test.log

Upload a file using Unofficially client in Python

# transfersh-cli (https://github.com/tanrax/transfersh-cli) $ transfersh photos.zip # Uploading file # Download from here: https://transfer.sh/xxxxxx/photos.zip # It has also been copied to the clipboard!

Encrypt your files with openssl before the transfer

# Encrypt files with password using openssl $ cat /tmp/hello.txt|openssl aes-256-cbc -pbkdf2 -e|curl -X PUT --upload-file "-" https://transfer.sh/test.txt # Download and decrypt $ curl https://transfer.sh/1lDau/test.txt|openssl aes-256-cbc -pbkdf2 -d > /tmp/hello.txt

Upload a file or directory in Windows

#Save this as transfer.cmd in Windows 10 (which has curl.exe) @echo off setlocal EnableDelayedExpansion EnableExtensions goto main :usage echo No arguments specified. >&2 echo Usage: >&2 echo transfer ^<file^|directory^> >&2 echo ... ^| transfer ^<file_name^> >&2 exit /b 1 :main if "%~1" == "" goto usage timeout.exe /t 0 >nul 2>nul || goto not_tty set "file=%~1" for %%A in ("%file%") do set "file_name=%%~nxA" if exist "%file_name%" goto file_exists echo %file%: No such file or directory >&2 exit /b 1 :file_exists if not exist "%file%\" goto not_a_directory set "file_name=%file_name%.zip" pushd "%file%" || exit /b 1 set "full_name=%temp%\%file_name%" powershell.exe -Command "Get-ChildItem -Path . -Recurse | Compress-Archive -DestinationPath ""%full_name%""" curl.exe --progress-bar --upload-file "%full_name%" "https://transfer.sh/%file_name%" popd goto :eof :not_a_directory curl.exe --progress-bar --upload-file "%file%" "https://transfer.sh/%file_name%" goto :eof :not_tty set "file_name=%~1" curl.exe --progress-bar --upload-file - "https://transfer.sh/%file_name%" goto :eof

Monday, May 3, 2021

How to update -grub from live-CD

 In order to update the grub configuration of the machine that you might be misconfigured and unable to boot up properly you could use live CD to boot into the machine, however, even if you are able to update the /etc/default/grub file, you will need to perform the "sudo update-grub" command to effect the change. if you are using Live CD to login, you need to perform the following steps:


First mount the root directory in question for my case it is my /dev/sda so it is it will be /dev/sda2 as mostly sda1 is for the /boot/efi partition.

You will mount the root partition as follow:

sudo mount /dev/sda2 /mnt

Then mount a few more directories that are needed:

sudo mount --bind /dev /mnt/dev
sudo mount --bind /sys /mnt/sys
sudo mount --bind /proc /mnt/proc
How can you tell if you have a boot partition?

Once you have your Ubuntu partition mounted, open /mnt/etc/fstab. If you see an entry for /boot, note which device it is pointing to (/dev/sda4 maybe?). This is the one you have to mount.

Once these are mounted, do chroot to start using the mounted directory as the root partition:

sudo chroot /mnt

You'll get a #/ prompt. First thing to do is confirm that you're using the correct /boot directory. Go to /boot/grub and look at the files there. There should be a bunch of .mod files and a grub.cfg file. If the directory is empty, don't continue, because it means this is NOT your actual boot directory. Look above to see how to determine if you need to mount an additional boot directory.

Once you've confirmed that /boot/ contains the correct files, meaning that it is the correct location, type:

sudo update-grub

This should rebuild your /boot/grub/grub.cfg file with the menu entries.

Then exit the chroot:

exit

At this point you may want to check that things were correctly updated. For this, cd /mnt/boot/grub and check that grub's files are there, there should be a bunch of .mod files and grub.cfg, the latter should have entries for your Ubuntu kernels. If you only see grub.cfg and no .mod files, it means that this is NOT the correct boot directory, look above for how to mount a separate boot partition.

Unmount the filesystems:

sudo umount /mnt/dev
sudo umount /mnt/sys
sudo umount /mnt/proc
sudo umount /mnt/

And then reboot, hopefully your Grub menu will be restored.


Tuesday, October 13, 2020

Single line network scanner with bash

for ip in 192.168.1.{1..254}; do for port in {21,22,80};do nc -zv -w 1 $ip $port &> /dev/null && echo "$ip at Port $port is up" || echo "$ip at port $port is down";done;done

Tuesday, June 16, 2020

Xerox Docuprint 203A with Raspberry Pi CUPS server

How to add Xerox Docuprint 203A to Raspberry Pi CUPS server

Xerox Docuprint 203A is a relatively old printer, in order to use raspberry pi as a print server for it, you need to obtain the right driver for linux arm for it to function properly.

You can never get the linux driver for it, as this is a very old printer, however the brother printer HL-2030 driver is a perfect replacement for it

Download it from here and import the PPD file and it will work magically well.


Thursday, September 14, 2017

Command to Flush DNS Cache in MacOS

sudo dscacheutil -flushcache
sudo killall -HUP mDNSResponder
say cache flushed

Checkpoint Firewall Ports

Check Point General Common Ports

PORTTYPESERVICE DESCRIPTION
257tcpFireWall-1 log transfer
18208tcpCPRID (SmartUpdate)
18190tcpSmartDashboard to SCS
18191tcpSCS to FW-1 gateway for policy install
18192tcpSCS monitoring of firewalls (SmartView Status)

Check Point SIC Ports

PORTTYPESERVICE DESCRIPTION
18209tcpNGX Gateways <> ICAs (status, issue, or revoke).
18210tcpPulls Certificates from an ICA.
18211tcpUsed by the cpd daemon (on the gateway) to receive Certificates.

PORTTYPESERVICE DESCRIPTION

94TCPEncryption IP protocols fwz_encapsulation (FW1_Eencapsulation)
137BothNetbios-ns NETBIOS Name Service
138Bothnetbios-dgm NETBIOS Datagram
139Bothnetbios-ssn NETBIOS Session
256TCPFW1 (fwd) policy install port FWD_SVC_PORT
257TCPFW1_log FW1_log FWD_LOG_PORT
258TCPFW1_mgmt FWM_SSVVC_PORT
259TCPFW1_clientauth_telnet
260UDPFW1_snmp FWD_SNMP_PORT
261TCPFW1_snauth Session Authentication Daemon
262TCPMDQ – mail dequer
263TCPdbs
264TCPFW1_topop Check Point SecureClient Topology Requests
265TCPFW1_key Check Point VPN-1 Public key transfer protocol

8116UDPCheck Point HA SyncMode= CPHAP (new sync mode)
8116UDPConnection table synchronization between firewalls
8989TCPCPIS Messaging MSG_DEFAULT_PORT
8998TCPMDS_SERVER_PORT
9000Command Line Port for Secure Client
10001TCPDefault CPRSM listener port for coms with RealSecure Console
18181TCPFW1_cvp Check Point OPSEC Content Vectoring Protocol
18182TCPFW1_ufp Check Point OPSEC URL Filtering Protocol
18183TCPFW1_sam Check Point OPSEC Suspicious Activity monitoring Proto (SAM API)
18184TCPFW1_lea Check Point OPSEC Log Export API
18185TCPFW1_omi Check Point OPSEC Objects Management Interface
18186TCPFW1_omi-sic Check Point OPSEC Objects management Interface with Secure Internal Communication
18187TCPFW1_ela Check Point OPSEC Event Loging API
18190TCPCPMI Check Point Management Interface
18191TCPCPD Check Point Daemon Proto NG
18192TCPCPD_amon Check Point Internal Application Monitoring NG
18193TCPFW1_amon Check Point OPSEC Appication Monitoring NG
18201TCPFGD_SVC_PORT
18202TCPCP_rtm Check Point Real time Monitoring
18203TCPFGD_RTMP_PORT
18204TCPCE communication
18205TCPCP_reporting Check Point Reporting Client Protocol
18207TCPFW1_pslogon Check Point Policy Server logon Protocol
18208TCPFW1_CPRID (SmartUpdate) Check Point remote Installation Protocol
18209TCPFWM CA for establishing SIC communication
18210TCPFW1_ica_pull Check Point Internal CA Pull Certificate Service
18211TCPFW1_ica_pull Check Point Internal CA Push Certificate Service
18212UDPConnect Control – Load Agent port
18213TCPcpinp: inp (admin server)
18214TCPcpsmc: SMC
18214UDPcpsmc: SMC Connectionless
18221TCPCP_redundant Check Point Redundant Management Protocol NG
18231TCPFW1_pslogon_NG Check Point NG Policy Server Logon Protocol
18231TCPNG listens on this port by default dtps.exe
18232TCPFW1_sds_logon Check Point SecuRemote Distribution Server Protocol
18233UDPCheck Point SecureClient Verification Keepalive Protocol FW1_scv_keep_alive
18241UDPe2ecp
18262TCPCP_Exnet_PK Check Point Public Key Resolution
18263TCPCP_Exnet_resolve Check Point Extranet remote objects resolution
18264TCPFW1_ica_services Check Point Internal CA Fetch CRL and User Registration Services
19190TCPFW1_netso Check Point OPSEC User Authority Simple Protocol
19191TCPFW1_uaa Check point OPSEC User Authority API
65524FW1_sds_logon_NG Secure Client Distribution Server Protocol (VC and Higher)

Command to check on Checkpoint Bond Interface status

[Expert@fw01:0]# cphaprob -a if

Required interfaces: 3
Required secured interfaces: 1

Mgmt       Disconnected          non sync(non secured), multicast
bond0      UP                    non sync(non secured), broadcast, bond Load Sharing
bond1      UP                    non sync(non secured), broadcast, bond Load Sharing
bond2      UP                    sync(secured), multicast, bond Load Sharing


[Expert@fw01:0]# cphaconf show_bond -a

                                      |Slaves     |Slaves |Slaves
Bond name  |Mode               |State |configured |in use |required
-----------+-------------------+------+-----------+-------+--------
bond0      | Load Sharing      | UP   | 2         | 2     | 1
bond1      | Load Sharing      | UP   | 2         | 2     | 1
bond2      | Load Sharing      | UP   | 1         | 1     | 0

Legend:
-------
UP!               - Bond interface state is UP, yet attention is required
Slaves configured - number of slave interfaces configured on the bond
Slaves in use     - number of operational slaves
Slaves required   - minimal number of operational slaves required for bond to be UP

[Expert@fw01:0]# cphaconf show_bond bond0

Bond name:      bond0
Bond mode:      Load Sharing
Bond status:    UP
Balancing mode: 802.3ad Layer3+4 Load Balancing
Configured slave interfaces: 2
In use slave interfaces:     2
Required slave interfaces:   1

Slave name      | Status          | Link
----------------+-----------------+-------
eth3-03         | Active          | Yes
eth3-01         | Active          | Yes

[Expert@fw01:0]# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.2.4 (January 28, 2008)

Bonding Mode: IEEE 802.3ad Dynamic link aggregation
Transmit Hash Policy: layer2 (0)
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 200
Down Delay (ms): 200

802.3ad info
LACP rate: slow
Active Aggregator Info:
        Aggregator ID: 1
        Number of ports: 2
        Actor Key: 33
        Partner Key: 1
        Partner Mac Address: 00:35:1a:d9:33:00

Slave Interface: eth3-03
MII Status: up
Link Failure Count: 1
Permanent HW addr: 00:1c:7f:61:90:50
Aggregator ID: 1

Slave Interface: eth3-01
MII Status: up
Link Failure Count: 1
Permanent HW addr: 00:1c:7f:61:90:4e
Aggregator ID: 1