Some Random but Useful Linux Commands

How to check the Linux OS version

lsb_release -a 
cat /etc/*lease

How to grep network traffic on a specific port or port range

ngrep -W byline -d eno3 -l -t -O dump.pcap  portrange 5060-6000 
ngrep -W byline -d eno3 -l -t -O dump.pcap  portrange 5060-6000  > debug.log
ngrep -W byline -d any -l -t -O dump.pcap  > debug.log
ngrep -W byline -d any -l portrange 5060-6000 and (ip[6:2] & 0x3fff != 0)
ngrep -W byline -d any -l -t -O dump.pcap  -F filter.txt > debug.log

Scan if remote port is open or not

nmap -sU 127.0.0.1 -p 9063 --reason
nmap -sT 127.0.0.1 -p 9062 --reason

Write string on socket

echo "HEP0BLABLABLABLABLA" | nc 127.0.0.1 9082

Delete journalctl logs

journalctl --vacuum-size=512M

How to copy lines in Vim with a mouse

set mouse-=a

Delete a row in Clickhouse-Database

alter table fraud_rules delete where uuid='0c026a6b-a4ef-48d6-b2e1-7066007554ab';
insert into users (username, partid,email,firstname,lastname,department,usergroup,hash) VALUES('admin','10','root@localhost','Hepic','Admin','Develop','admin','$2a$10$yAltOkF7vWTjBM74DetN4./pygRlAYzV.Dgg0GwVHD466d3b0.Qe.');

How to add firewall rules using firewalls

firewall-cmd --zone=public --add-port={5060/udp,18091/tcp,80/tcp,20000-30000/udp,9000/tcp,9062/tcp,18100/tcp}


How to create a quick openssl self-signed certificate

openssl req -new -x509 -nodes -out \
/etc/openldap/certs/myldap.field.linuxhostsupport.com.cert \
-keyout /etc/openldap/certs/myldap.field.linuxhostsupport.com.key \
-days 365

Save Curl output to a file

curl -X POST http://127.0.0.1:18100/api/hepsub/request \
   -H 'Content-Type: application/json' \
   -d '{"uuid":"375fd72a-f051-4cfd-916f-bca3c69fff96","liid":127,"sid":0,"correlation_id":"313633343635353333373530363238-d60yef8r2znw","direction":0,"record_datetime":"2021-10-19T16:55:42+02:00","storedir":"/home/hrhashmi/","src_ip":"92.200.216.135","src_port":53176,"dst_ip":"136.243.16.181","dst_port":20714,"time_sec":1634655342,"time_usec":641247,"proto":17,"ssrc":0,"filename":"rtp_255_0_1633611342651_3502669417_3a8bb82063616c6c02053961@204.197.191.183.pcap","node":"node-botauro","create_date":0,"date":"20211019","type":"mp3","active":true}' \
   --output file.mp3


How to create new MySQL DB USER

SELECT user,authentication_string,plugin,host FROM mysql.user;
create user user@localhost;
grant all privileges on . to user@localhost;
ALTER USER 'user'@'localhost' IDENTIFIED WITH mysql_native_password BY '';
FLUSH PRIVILEGES;

How to connect Clickhouse-Database

clickhouse-client --host 127.0.0.1 --user default --password `cat /etc/clickhouse-server/users.xml | grep "<password>"|  awk '{ print $1 }' | grep -v Example: | sed 's/<password>//g' | sed 's/<\/password>//g'` -d hepic_data


How to restore Clickhouse-Database

sudo -u clickhouse touch /var/lib/clickhouse/flags/force_restore_data

Check Disk Usage

du -cha --max-depth=1 /var | grep -E "M|G"

Hepgen Tool

pcap2hepgen.js /home/hamid/export_manuallCorrelation.txt /home/hamid/export_manuallCorrelation.js
hepgen.js -s 127.0.0.1 -p 9063 -c /home/hamid/export_manuallCorrelation.js

find and delete some specific files

find / -name clickhouse-* | xargs rm -f

How to top a specific service

 top -p $(pidof clickhouse-server) -H -n 5 > Clickhouse-server.txt

Disk Performance

fdisk -l
hdparm -T /dev/sda1
hdparm -t /dev/sda1

Steno type query

stenotype --preallocate_file_mb=20 --blocks=128 --seccomp=none -v --threads=1 --iface=eth0 --dir=/data/stenographer --fileage_sec=1200 --blockage_sec=30


Kill a TCP connection

iptables -A OUTPUT -p tcp --dport 9062 -j REJECT
ss -K dport = 9062

Restore a TCP Connection

iptables -D OUTPUT -p tcp --dport 9062 -j REJECT

File Symlink

unlink filename
ln -vfns /remote/filename filename

How to Read json file in bash

cat /usr/local/hepic/etc/hepicapp_config.json | jq '.loki_config'

Enjoy ;)

No comments:

Post a Comment

SIPp UAC Scenario to send RTP

Please install the latest sipp ( >=3.7.3 ) wget https://github.com/SIPp/sipp/releases/download/v3.7.3/sipp chmor +x sipp mv sipp /usr/bin...