Identify OS on remote host

For nmap to even make a guess, nmap needs to find at least 1 open and 1 closed port on a remote host. Using the previous scan results, let us find out more about the host 192.168.0.115:

# nmap -O -sV 192.168.0.115

Output:

Starting Nmap 7.80 ( https://nmap.org ) at 2020-10-02 12:21 CEST
Nmap scan report for 192.168.0.115
Host is up (0.00023s latency).
Not shown: 991 closed ports
PORT      STATE SERVICE     VERSION
22/tcp    open  ssh         OpenSSH 5.1 (protocol 2.0)
80/tcp    open  http        Apache httpd 2.2.19 ((Unix) mod_ssl/2.2.19 OpenSSL/0.9.8zf DAV/2)
111/tcp   open  rpcbind     2 (RPC #100000)
139/tcp   open  netbios-ssn Samba smbd 3.X - 4.X (workgroup: WORKGROUP)
443/tcp   open  ssl/http    Apache httpd 2.2.19 ((Unix) mod_ssl/2.2.19 OpenSSL/0.9.8zf DAV/2)
445/tcp   open  netbios-ssn Samba smbd 3.X - 4.X (workgroup: WORKGROUP)
873/tcp   open  rsync       (protocol version 29)
2049/tcp  open  nfs         2-4 (RPC #100003)
49152/tcp open  upnp        Portable SDK for UPnP devices 1.6.9 (Linux 2.6.39.3; UPnP 1.0)
MAC Address: 00:26:2D:06:39:DB (Wistron)
Device type: general purpose
Running: Linux 2.6.X|3.X
OS CPE: cpe:/o:linux:linux_kernel:2.6 cpe:/o:linux:linux_kernel:3
OS details: Linux 2.6.38 - 3.0
Network Distance: 1 hop
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel:2.6.39.3


OS and Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 14.58 seconds

nJoy 😉

Clear Linux Cache

1. Clear PageCache only.

# sync; echo 1 > /proc/sys/vm/drop_caches

2. Clear dentries and inodes.

# sync; echo 2 > /proc/sys/vm/drop_caches

3. Clear PageCache, dentries and inodes.

# sync; echo 3 > /proc/sys/vm/drop_caches 

nJoy 😉

Show all cronjobs for all users

This is a simple script to get all cronjbs for all users on a system

for someone in $(cut -f1 -d: /etc/passwd); do echo $someone; crontab -u $someone -l ; done

nJoy 😉

 

Create windows 10 boot disk on almost any linux host

Mount the ISO:

sudo mount -t udf -o loop,ro,unhide /path/to/file.iso /mnt

Insert the USB drive.
Run fdisk and specify the device name of the USB drive; for example:

sudo fdisk /dev/sdc

Delete any existing partition table and create a new one.
Create a new partition of at least 4.5 GB. Mark it bootable and set its type to 7 (HPFS/NTFS/ExFAT).
Write changes and exit fdisk.
Create a FAT-32 file system in the new partition; for example:

sudo mkfs.vfat -F 32 /dev/sdc1

Mount this partition to an existing subdirectory; for example:

sudo mount /dev/sdc1 /media/usbstick

Copy all of the files from the mounted ISO into this directory:

sudo cp -rv /mnt/* /media/usbstick

Sync the file systems just to be sure:

sudo sync

Unmount both items previously mounted:

sudo umount /media/usbstick
sudo umount /mnt

nJoy 😉

 

Backup and Restore Elastic search

While elastic search is usually run as a cluster, for the sake of this tutorial I am showing the _snapshot and _restore tools.

 

mkdir  /mnt/backups/my_backup
chmod 777 -R /mnt/backups/

Must available on all nodes.


 curl -XPUT 'http://localhost:9200/_snapshot/my_backup' -d '{
 "type": "fs",
 "settings": {
        "location": "/mnt/backups/my_backup",
   "compress": true
    }
}'






[root@centos-base mnt]# curl -XGET 'http://localhost:9200/_snapshot/my_backup?pretty'

{
  "my_backup" : {
    "type" : "fs",
    "settings" : {
      "compress" : "true",
      "location" : "/mnt/backups/my_backup"
    }
  }
}



 curl -XGET 'http://localhost:9200/_snapshot?pretty'                                       {
  "my_backup" : {
    "type" : "fs",
    "settings" : {
      "compress" : "true",
      "location" : "/mnt/backups/my_backup"
    }
  }
}

_____________________________________________________________________________________________

changing


 curl -XPUT 'http://localhost:9200/_snapshot/my_backup' -d '{
 "type": "fs",
 "settings": {
  "location": "/mnt/backups/my_backup",
 "compress": true,
 "verify":true
	}	
	}'


 curl -XPUT "localhost:9200/_snapshot/my_backup/snapshot_`date | tr -d " " | tr -d ":" | tr '[:upper:]' '[:lower:]' `?wait_for_completion=true&pretty"
 
 

 
_____________________________________________________________________________________________

restoring

 mkdir -p /mnt/backups/my_backup
 chmod -R 777 /mnt/backups/

 
 Create repository
 -----------------------
 
 curl -XPUT 'http://localhost:9200/_snapshot/my_backup' -d '{
 "type": "fs",
 "settings": {
  "location": "/mnt/backups/my_backup",
 "compress": true,
 "verify":true
	}	 
	}'

	
 restore from file system
 --------------------------------
 
  curl -XPOST "localhost:9200/_snapshot/my_backup/snapshot_satapr25223454cest2015/_restore"

nJoy 😉

fstab entry for sshfs

Sample entry

root@192.168.168.100:/mnt/streamstorage53/stage.k/ura/web /opt/kaltura/web fuse.sshfs _netdev,auto 0 0

 

nJoy 😉

 

Auto-blacklist iptables

Gather a list of ips which fail logins and drop from firewall for the future

lastb | awk '{ FS == "[ \t]+" ; print $3; }' | egrep -o '([[:digit:]]{1,3}\.){3}[[:digit:]]{1,3}'| grep -v "192.168." | sort | uniq | xargs -n 1 -I {} iptables -A INPUT -s {} -j DROP

if you want to make it permanent simply

[root@DellR510-3 ~]# /sbin/service iptables save

 

That’s it.

nJoy 😉

 

 

 

Replacing a piece of XML with awk

This script searches for an initial tag and and closing one and replaces the content.

# !/bin/bash
awk ‘
BEGIN {pr = 1;one = 0}
/<Name>OPENING<\/Name>/ {pr = 0;}
{ if (pr) print }
{ if (!pr && !one) {print (“\t\t <Name>OPENING</Name> \n \t\t\t <Value>false</Value> \n \t\t<Type>STOPHERE</Type> \n ” ); one =1 ;}}
/<Type>STOPHERE<\/Type>/ {pr = 1;}
‘< $1

Not the most elegant solution but lends itself to multiple replacements.

 

find . | grep file.xml | xargs -I {J} -n 1 bash -c ‘ ./aw.sh {J} > {J}.new ; mv -f {J}.new {J}  ‘

nJoy 😉