Skip to content

Instantly share code, notes, and snippets.

@PSJoshi
PSJoshi / shell-change.md
Created July 20, 2022 07:07
Use different shell with su

Use different shell with su

$ su -s /bin/bash <user>
@PSJoshi
PSJoshi / log-shell-commands.md
Created March 24, 2022 12:09
Log every shell command in linux

Log every shell command in linux

  • Using Bash shell option Add ‘shopt -s syslog_history‘ into system-wide startup /etc/profile or personal initialization file - ~/.bash_profile
      [root@joshi ~]# cat /etc/profile | grep shopt
      shopt -s syslog_history
    
  • Using rsyslog service
    • Create a new rsyslog configuration file, and define the log file path. For example: /var/log/shell-commands.log.
@PSJoshi
PSJoshi / remove-osquery.md
Created March 6, 2022 10:42
Remove OSquery agent on linux
$ sudo systemctl stop osqueryd.service
$ sudo yum remove osquery
$ sudo rm -rf /var/osquery /var/log/osquery /etc/osquery

@PSJoshi
PSJoshi / nmap-xml-json.md
Last active September 19, 2024 04:58
convert nmap XML to JSON

Step 1:

Do nmap scan of the target

# nmap -sV -oX nmap_out.xml example.com 1>/dev/null 2>/dev/null

Step 2:

Convert nmap's XML output to JSON so that it can be fed to ELK stack.

#!/usr/bin/env python
@PSJoshi
PSJoshi / mem-usage.sh
Last active August 5, 2022 06:16
memory utilization per process
#!/bin/bash
# other interesting memory utilization scripts
# https://github.com/jhclark/memusg
# https://github.com/shovon8/sysmon/blob/master/sysmon
# https://gist.github.com/taoliu/1572440
mem_info=$(ps -o pid,user,%mem,command ax | grep -v PID | awk '/[0-9]*/{print $1 ":" $2 ":" $3 ":" $4}')
@PSJoshi
PSJoshi / docker-socket-error.md
Created December 12, 2021 09:51
Docker daemon socker error

Error - Docker: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock

This error is because present unprivileged user does not belong to the docker group.

So, you can do this:

$ sudo usermod -a -G docker [user]

You can check it was successful by doing grep docker /etc/group and see something like this:

@PSJoshi
PSJoshi / cron-script-output.md
Created December 2, 2021 06:01
Description of cron script output options

Cron script output options

$ crontab -e
59 23 * * * /home/joshi/bin/backup.sh > /home/joshi/logs/backup.log 2>&1

In the above:

  • /home/joshi/logs/backup.log indicates that the standard output of the backup.sh script will be redirected to the backup.log file.

  • 2>&1 indicates that the standard error (2>) is redirected to the same file descriptor that is pointed by standard output (&1). So, both standard output and error will be redirected to /home/joshi/logs/backup.log
@PSJoshi
PSJoshi / OpenSSL.md
Created April 8, 2021 09:39 — forked from mohanpedala/OpenSSL.md
OpenSSL Working with SSL Certificates, Private Keys, CSRs and Truststores

Generate a private key and a CSR(Certificate Signing Request )

Use this method if you want to use HTTPS (HTTP over TLS) to secure your Apache HTTP or Nginx web server, and you want to use a Certificate Authority (CA) to issue the SSL certificate. The CSR that is generated can be sent to a CA to request the issuance of a CA-signed SSL certificate. If your CA supports SHA-2, add the -sha256 option to sign the CSR with SHA-2.

Creating a 2048-bit private key (domain.key) and a CSR (domain.csr) from scratch:

openssl req -newkey rsa:2048 -nodes -keyout domain.key -out domain.csr

Creating a 2048-bit private key and public key

@PSJoshi
PSJoshi / nuclei.md
Last active March 23, 2021 09:56
Using nuclei to scan vulnerabilities

Nuclei is becoming a de-facto tool for configurable targeted scanning based on templates offering massive extensibility and ease of use. It is often used to send requests across targets based on a template leading to zero false positives and providing effective scanning for known paths. The tool is essentially useful during initial reconnaissance phase to quickly check for low hanging fruits or CVEs across targets that are known and easily detectable.

Installation

@PSJoshi
PSJoshi / apache-superset.md
Last active February 23, 2021 10:45
Installation of apache superset

Install Apache superset

  • Install required OS packages
$ sudo apt-get install build-essential libssl-dev libffi-dev python3.7-dev python-pip libsasl2-dev libldap2-dev
  • Upgrade pip
pip install --upgrade setuptools pip