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 ;)

RTPProxy Installation Steps

RTPProxy Installation Steps

git clone --recursive --no-single-branch --branch rtpp_2_2 https://github.com/sippy/rtpproxy.git 
cd rtpproxy 
./configure --prefix=/usr/local/rtpproxy/ 
make
make install 
cp rpm/rtpproxy.service /etc/systemd/system/ 
sed -i 's/\/usr\/bin\/rtpproxy/\/usr\/local\/rtpproxy\/bin\/rtpproxy/1' /etc/systemd/system/rtpproxy.service 
sed -i 's/\/var\/run\/rtpproxy\/rtpproxy.pid/\/usr\/local\/rtpproxy\/var\/run\/rtpproxy\/rtpproxy.pid/g' /etc/systemd/system/rtpproxy.service 

For Debian:

cp rpm/rtpproxy.sysconfig /etc/default/rtpproxy 
sed -i 's/sysconfig/default/1' /etc/systemd/system/rtpproxy.service 

For CentOS:

cp rpm/rtpproxy.sysconfig /etc/sysconfig/rtpproxy 

Create User and add some options

mkdir -p /usr/local/rtpproxy/var/run/rtpproxy/ 
chown -R rtpproxy:rtpproxy /usr/local/rtpproxy 
groupadd rtpproxy 
useradd -M rtpproxy -g rtpproxy 
echo "OPTIONS=\"-s /usr/local/rtpproxy/var/run/rtpproxy/rtpproxy.sock -l 192.168.0.132 -t 184 -m 20000 -M 30000 -s udp:127.0.0.1:7722 -d INFO LOG_LOCAL0\"" > /etc/default/rtpproxy 

Now start RTPProxy

systemctl daemon-reload 
systemctl start rtpproxy 

To run rtpproxy directly from command line

/usr/local/rtpproxy/bin/rtpproxy -p /usr/local/rtpproxy/var/run/rtpproxy/rtpproxy.pid -s /usr/local/rtpproxy/var/run/rtpproxy/rtpproxy.sock -l 192.168.0.132 -t 184 -m 20000 -M 30000 -s udp:127.0.0.1:7722 -u rtpproxy:rtpproxy 

Enjoy ;)

RTCAgent Installation Steps

RTCAgent v0.0.3 installation steps

wget https://github.com/sipcapture/rtcagent/releases/download/v0.0.3/rtcagent_v0.0.3_all.deb 
dpkg -i rtcagent_v0.0.3_all.deb 

Create a service file for RTCagent

cat > /etc/systemd/system/rtcagent.service <<EOF 
[Unit]
Description=Captures packets with eBPF Filter and sends them to Homer
After=network.target

[Service]
ExecStart=/usr/bin/rtcagent kamailio -m /opt/kamailio/sbin/kamailio --hep-server="127.0.0.1" --hep-port="9060" --hep-transport="tcp"
ExecStop=/bin/kill ${MAINPID}
Restart=on-failure
RestartSec=10s
Type=simple

[Install]
WantedBy=multi-user.target
EOF

to run RTCAgent in foreground run with this command

rtcagent kamailio -m /opt/kamailio/sbin/kamailio --hep-server="nyc02.sipcapture.io" --hep-port="9082" --hep-transport="TCP" 

Enjoy ;)

Kamailio v 5.7.1 installation Steps (HBVideo Audio/Video Solution)

Installation Steps Kamailio v5.7.1

wget https://www.kamailio.org/pub/kamailio/latest/src/kamailio-5.7.0_src.tar.gz 
tar -xf kamailio-5.7.0_src.tar.gz 
cd kamailio-5.7.0 
apt install libunistring-dev bison flex 
make PREFIX="/opt/kamailio" include_modules="db_mysql tls websocket xmlrpc http_client" cfg 
make Q=0 all 
make install 
cp pkg/kamailio/deb/debian/kamailio.service /etc/systemd/system/ 
cp pkg/kamailio/deb/debian/kamailio.default /etc/default/kamailio 
mkdir -p /opt/kamailio/var/run/kamailio/ 
sed -i 's#/etc/kamailio/kamailio.cfg#/opt/kamailio/etc/kamailio/kamailio.cfg#1' /etc/systemd/system/kamailio.service 
sed -i 's#/usr/sbin/kamailio#/opt/kamailio/sbin/kamailio#1' /etc/systemd/system/kamailio.service 
sed -i 's#/run/kamailio/kamailio.pid#/opt/kamailio/var/run/kamailio/kamailio.pid#1' /etc/systemd/system/kamailio.service 
useradd -M kamailio 
chown -R kamailio:kamailio /opt/kamailio 
systemctl daemon-reload 
systemctl start kamailio 
systemctl status kamailio 

Create Database: Uncomment mysql components from the following file

vim /opt/kamailio/etc/kamailio/kamctlrc 

DBENGINE=MYSQL

DBHOST=localhost

DBPORT=3306

DBNAME="kamailio"

DBUSER="kamailio"

DBRWPW="kamailio"

Now execute the following command to create kamaillio Database

/opt/kamailio/sbin/kamdbctl create

Deploy Kamailio Configuration

git clone https://github.com/hamidrhashmi/HBvideo 
cd HBvideo/ 
cp * -r /opt/kamailio/etc/kamailio/ 
cd /opt/kamailio/etc/kamailio/ 
sed -i 's/192.168.0.132/PUBLIC-IP/g' kamailio.cfg && sed -i 's/192.168.0.132/PUBLIC-IP/g' tls.cfg
sed -i 's/kamailio.hbvoice.local/DOMAIN/g' kamailio.cfg
grep "ALTER TABLE" kamailio.cfg > update.sql
mysql -u kamailio -p kamailio < update.sql
systemctl restart kamailio

Add New SIP User

/opt/kamailio/sbin/kamctl add 12345@DOMAIN 1234543210
/opt/kamailio/sbin/kamctl add 54321@DOMAIN 1234543210

Upgradation Steps to Kamailio v5.8.1

systemctl stop kamailio
wget https://www.kamailio.org/pub/kamailio/latest/src/kamailio-5.8.1_src.tar.gz
tar -xvf kamailio-5.8.1_src.tar.gz
cd kamailio-5.7.0 
apt install libunistring-dev bison flex 
make PREFIX="/opt/kamailio" include_modules="db_mysql tls websocket xmlrpc http_client" cfg 
make Q=0 all 
make install
/opt/kamailio/sbin/kamailio -V
systemctl start kamailio
systemctl status kamailio

Enjoy 😉


Debugging Step

/opt/kamailio/sbin/kamailio -f /opt/kamailio/etc/kamailio/kamailio -D -d 2 -E

In Case you have to install some missing module use the following command

make install-modules modules=modules/xmlrpc

Good Luck 👍

RTPEngine Installation Steps for Debian

RTPEngine 11.3.1 installation steps

apt-get install aptitude dpkg-dev lsb-release markdown nfs-common netcat netcat-openbsd 
cd /usr/local/src 
git clone --single-branch --branch mr11.3.1 https://github.com/sipwise/rtpengine.git 
export DEB_BUILD_PROFILES="pkg.ngcp-rtpengine.nobcg729" 
cd rtpengine 
apt install dpkg-dev aptitude 
dpkg-buildpackage 
dpkg-checkbuilddeps 
aptitude install debhelper default-libmysqlclient-dev gperf iptables libxtables-dev libavcodec-dev libavfilter-dev libavformat-dev libavutil-dev libbencode-perl libcrypt-openssl-rsa-perl libcrypt-rijndael-perl libcurl4-openssl-dev libcurl4-gnutls-dev libdigest-crc-perl libdigest-hmac-perl libevent-dev libglib2.0-dev libhiredis-dev libio-multiplex-perl libio-socket-inet6-perl libiptc-dev libjson-glib-dev libnet-interface-perl libpcap-dev libpcre3-dev libsocket6-perl libspandsp-dev libssl-dev libswresample-dev libsystemd-dev libxmlrpc-core-c3-dev 
aptitude install dh-sequence-dkms libjson-perl libmosquitto-dev libopus-dev libtest2-suite-perl libwebsockets-dev python3-websockets markdown 
cpan install Config::Tiny 
ldconfig 
dpkg-buildpackage 
cd .. 
ls | grep -v dbgsym | grep .deb | xargs dpkg -i

Stop and disable Disable RTPengine recording service

systemctl stop rtpengine-recording 
systemctl disable rtpengine-recording 

Start RTPengine Service

systemctl restart rtpengine

RTPEngine service will listening on the following ports by default

tail -f /var/log/syslog -n 1000 | grep rtpengine 
netstat -nlp | grep rtpengine 
tcp        0      0 127.0.0.1:2224          0.0.0.0:*               LISTEN      35778/rtpengine 
tcp        0      0 127.0.0.1:2225          0.0.0.0:*               LISTEN      35778/rtpengine 
tcp6       0      0 ::1:2224                :::*                    LISTEN      35778/rtpengine 
tcp6       0      0 ::1:2225                :::*                    LISTEN      35778/rtpengine 
udp        0      0 127.0.0.1:2223          0.0.0.0:*                           35778/rtpengine 
udp6       0      0 ::1:2223                :::*                                35778/rtpengine

and it will also add iptable module and rule by itself

tail -f /var/log/syslog -n 1000 | grep rtpengine 
netstat -nlp | grep rtpengine 
tcp        0      0 127.0.0.1:2224          0.0.0.0:*               LISTEN      35778/rtpengine 
tcp        0      0 127.0.0.1:2225          0.0.0.0:*               LISTEN      35778/rtpengine 
tcp6       0      0 ::1:2224                :::*                    LISTEN      35778/rtpengine 
tcp6       0      0 ::1:2225                :::*                    LISTEN      35778/rtpengine 
udp        0      0 127.0.0.1:2223          0.0.0.0:*                           35778/rtpengine 
udp6       0      0 ::1:2223                :::*                                35778/rtpengine

Enjoy ;)

How to compile and run a next application ?

Install nodejs Use  this  link for further reading curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash nvm inst...