List all files and first level directories arranged by size on Linux

du -sh * | sort -hr

Where:

  • du -sh: Shows the sizes of files and directories in a human-readable format
  • sort -hr: Sorts the output by size in human format, with the largest items at the top.

Sample:

That’s it, Enjoy!

Posted in Linux | Tagged , | Leave a comment

Mount shared folder inside Kali Linux VM on VMware Workstation

Create a share from your Virtual Machine Settings, let’s call it shared_vm

sudo apt install open-vm-tools # Make sure you have the latest vmware tools installed
sudo mkdir /shared_vm
sudo /usr/bin/vmhgfs-fuse .host:/ /shared_vm -o subtype=vmhgfs-fuse,allow_other # Mounts the shared_vm share to /shared_vm

To make it permanent, add it to /etc/fstab as follows:

vmhgfs-fuse /mnt/hgfs fuse defaults,allow_other 0 0

Tested on the following environment:

  • Host: Windows 11 Pro x86-64 Host
  • Guest: Kali 2024.3 x86-64
  • Hypervisor: VMware Workstation 16.2.5 Pro

That’s it, Enjoy!

Sources: VMware Official Docs

Posted in Linux | Tagged , , , | Leave a comment

Script to grab sizes of GCP buckets

Prerequisites:

  • Google Cloud SDK Installed & Configured

For a simple script that just does the job and gets the sizes of all your buckets:

for bucket in $(gsutil ls); do
  echo "Bucket: $bucket"
  gsutil du -sh $bucket
done

For a more comprehensive script that picks a specific set of buckets and saves the output to a file:

#!/bin/bash

# File to save the output
output_file="bucket_sizes.txt"

# List of specific buckets
buckets=(
  "gs://bucket1/"
  "gs://bucket2/"
  "gs://bucket3/"
  "gs://bucket4"
)

# Clear the output file if it exists, or create a new one
> $output_file

# Loop through the list and get the size of each bucket
for bucket in "${buckets[@]}"; do
  echo "Bucket: $bucket" >> $output_file
  gsutil du -sh $bucket >> $output_file
done

# Print a message indicating that the process is complete
echo "Bucket sizes have been saved to $output_file"

That’s it, Enjoy!

Posted in Linux | Tagged , , | Leave a comment

How to enable Python to craft packets and listen to ports less than 1024 without sudo

To be able to craft packets with Scapy, you have to either use sudo or allow setcap for your python environment. I don’t prefer to use sudo when working with my Anaconda environments, so I did the following:

sudo setcap 'cap_net_raw,cap_net_admin,cap_net_bind_service=eip' /home/ubuntu/anaconda3/envs/py311/bin/python3.11

Note: Using in the above example python instead of python3.11 won’t work, since python in that location is just a symbolic link, you have to specify the executable itself directly.

That’s it, now you can run your program without sudo!

Enjoy!

Posted in Linux | Tagged , , | Leave a comment

How to run wireshark/tshark or tcpdump to capture packets inside IPMininet using screen

This has been a bit confusing for some time, but after you run your ipmininet network with Python, you want to capture some packets with wireshark/tshark or tcpdump, here is the way you can do it:

Let’s assume we have a host named h1, now at the prompt of mininet:

mininet> h1 screen -S tcpdump

This will take you to a screen terminal where you can run tshark or tcpdump inside it, then Press Ctrl+A then D to detach from out.

After that do whatever command you want, e.g. h1 wants to ping h2

mininet> h1 ping h2

After you are done and you want to collect the results, just run:

mininet> h1 screen -r

you will find the results captured by tcpdump there, which you can copy or screenshot or whatever you want. Finally type exit to destroy the screen session.

Enjoy!

Note: I was using the vagrant installation method of ipmininet.

Thanks Jeril for the tip 😉

Posted in Linux | Tagged , , , , , | Leave a comment