Change priority of preferred networks

It is bothering sometimes when you’re connecting to the network you wish to, but suddenly your machine (macbook, laptop…) automatically switches to other network with stronger signal (for example).

To fix to the network (specifically for WiFi connection), you can manage the priority (or order) by the followings:

  1. For MacBook user: System Preferences –> Network –> Advanced… –> Under Preferred Networks, drag networks into the order you prefer –> click OK to finish
  2. For Windows user: Control Panel –> Network and Sharing Center –> Manage Wireless Networks –> now you can move up or down to find the priority you want

Now, that’s it :) the network you intent to connect to will not be switched to other even it has a little lower signal…

How to install USB wireless dongle on Kali Linux or Ubuntu

For this tutorial, I have a DWA-182 USB wireless dongle which is one of the affordable devices that we can start with when getting into Wireless hacking/pen testing on Kali Linux.

Now, I’ll show you how to get it works.

My scenario:

  • I have Kali 2017.3 32 bit as installed on Virtualbox on Macbook air (early 2015)
  • I have DWA-182 (rev. C1) USB wireless dongle connected my Kali VM from my Mac (refer to below figure)

Screen Shot 2018-01-30 at 3.51.25 AM

How to get your WiFi working

  1. Log in as super user root with password toor
  2. Open terminal and issue
$ lsusb (you should see D-Link adapter)
$ apt update && apt upgrade -y
$ apt install realtek-rtl88xxau-dkms -y (rtl8812au-dkms for ubuntu)
$ reboot
==== after reboot ===
$ ifconfig (you should see wlan0 now)
$ ifconfig wlan0 down
$ iwconfig wlan0 mode monitor
$ ifconfig wlan0 up
$ tcpdump -I -i wlan0 -w ~/my-trace.pcap (listen packets on air)

Screen Shot 2018-01-30 at 3.44.24 AM

*** note that to know which chipset drivers to install, you can check here:

https://wikidevi.com/wiki/D-Link_DWA-182_rev_C1

Then you’ll see that DWA-182 uses Realtek RTL8812AU

How to capture packets on your Mac

If you know how to read a packet trace, you may find it useful when diagnosing issues with a network connection.

Get the BSD device name of the network interface

  1. Log in to your Mac with an administrator account.
  2. While holding down the Option key, then choose Apple menu () > System Information (or System Profiler).
  3. Select Network from the list on the left side of the System Information window.
  4. Select the network interface (such as Wi-Fi or Ethernet) from the list of active services on the right side of the window.
  5. From the details section at the bottom of the window, find “BSD Device Name.” In the example pictured, the BSD device name for Wi-Fi is en0.

System Information window

Capture the packet trace

  1. Open Terminal, which is in the Utilities folder of your Applications folder,.
  2. Type the following command, but replace BSDname with the BSD device name (such as en0, en1, or ppp0) from System Information:sudo tcpdump -i BSDname -s 0 -B 524288 -w ~/Desktop/DumpFile01.pcap
  3. Press Return, then enter your administrator password when prompted.
  4. Terminal should say tcpdump: listening on... to indicate that it’s listening for activity on that network interface.
  5. While Terminal is open, perform the network function that you want to test.
  6. When the network function is complete, return to Terminal and press Control-C to capture the packet trace. Terminal saves it to your desktop in a file named “DumpFile01.pcap.”
  7. To see the contents of the file, use this command in Terminal:tcpdump -iBSDname -s 0 -n -e -x -vvv -r ~/Desktop/DumpFile01.pcap
    or if you have Wireshark/tshark installed, you can issue: wireshark ~/Desktop/DumpFile01.pcap
  8. To capture additional packet traces, modify the Terminal command to increment the number of the saved file (such as DumpFile02.pcap and DumpFile03.pcap).

You can also use other built-in Mac utility named airport to do the same thing as above, but first, you need to create a link to it to make it easy to use:

sudo ln -s /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport /usr/local/bin/airport

Then, you can scan the network and capture:

airportBSDname scan sudo airport en1 sniff 6

or graphically, you can use “Wireless Diagnostics” utility:

Screen Shot 2018-01-29 at 9.46.00 AM

Create Multiple Users in Linux using Python script

The last post for years, I showed how to create multiple in Linux using a shell script. But the limitation is that every user needs to use the same given password. This time, I’ll show you how to create multiple users in Linux using Python script. I know that most of Linux (maybe all, if I’m not wrong) come with Python (.py) as default as Shell script (.sh), so you don’t need to worry if you need to install additional Python package.

E.g. Create three users (john, richhat, jackie) with its own password. Here is how, you need to run a script called multiUser.py followed by user_pass.txt that contains user and password:

$ python multiUser.py user_pass.txt

You can name the file anything you wish and below is the content of each file:

multiUser.py

import sys
import os
import string
import random
import crypt

# function for create one user with supplied password
def createUser(name,passwd):
   two = ''.join(random.choice(string.ascii_letters) for x in range(2))
   encPass = crypt.crypt(passwd, two)
   os.system("useradd -p "+encPass+ " -m "+name)

# main program
if __name__ == '__main__':
   # prepare variables like file name and lists of user and password
   fname = sys.argv[1]
   list_users = []
   list_passwds = []
   # read username and password from file and save to the created lists
   with open(fname,'r') as file:
      for line in file:
         list_temp = line.rstrip('\n').split(" ")
         list_users.append(list_temp[0])
         list_passwds.append(list_temp[1])
   # start creating users
   for i,user in enumerate(list_users):
      createUser(list_users[i],list_passwds[i])

user_pass.txt (separate username and password by space)

john 1234
richhat secret123
jackie 1234567

How to dual boot Kali on Macbook and Fix WiFi problem

This is a brief note of how I dual boot Kali Linux on Macbook air early 2015 and how I fixed WiFi problem

::DUAL BOOT KALI::

Before you do, you might be interested to have a look at this video or official guide (the steps are different, but it gives an idea)

1. Prepare a minimum 20 GB of HDD from Machintosh HDD (Partition, add partition)
2. Prepare a USB bootable of Kali Linux
3. Reboot and hold option key, you’ll get into a boot menu where you can select your USB drive
4. Select Live Kali, open GParted, resize the USB drive to make sure that there is no additional unallocated space on it, otherwise, it gonna mess up because you might not select the right space to install.
5. Reboot, again hold option key to get to menu again, select USB
6. Select Kali installer
7. From here, make you you can connect to Internet because you require your Kali to work especially when install Boot loader.
8. Partitioning is an important part, make sure you select the right free (unallocated space 20GB or whatever you spare)
– partition
9. Then just next and next follow the normal process until finish and reboot; YOU’ve DONE!!!

:: FIX WIFI::

After installation finish, you will face a serious problem that WiFi doesn’t work, so follow this:

Before you get started, you can check if your WiFi adapter present and to see its chipset:

$ lspci | grep Wireless
03:00.0 Network controller: Broadcom Limited BCM4360 802.11ac Wireless Network Adapter (rev 03)

1. add “deb http://http.kali.org/kali kali-rolling main contrib non-free” to /etc/apt/sources.list
2. update it and upgrade as well (make sure you connect to internet access by ethernet USB or else): apt update && apt upgrade -y

if it turns out error, you might follow advice from error, you might run: apt –fix-broken install

3. Install some required packages (hopefully, this might work for you or might not since I try many)

$ apt install linux-image-$(uname -r|sed 's,[^-]*-[^-]*-,,') linux-headers-$(uname -r|sed 's,[^-]*-[^-]*-,,')
$ apt install broadcom-sta-dkms
$ modprobe -r b44 b43 b43legacy ssb brcmsmac bcma
$ modprobe -r wl && modprobe wl

*** The last line is what makes your WiFi works, this it might turn out error, but then just reboot, it works for me and it should work for you too. If not, you might try to search more so that “wl” module can be loaded :)

How to clone raspberry pi (rasbian) image from microSD to Disk

When you create a raspberry pi (rasbian) boot microSD, you do this way:

  • Don’t forget to u(n)mount the microSD before doing anything…, in my case I use macOS (use umount command in Linux)
sudo diskutil umountDisk /dev/disk3
sudo dd bs=1m if=~/Desktop/raspbian-stretch-lite.img of=/dev/disk3
  • This will copy image from Desktop to microSD which is /dev/disk3

What if you want to save (clone) image back to disk from microSD? Simple!!! Just flip the location between if and of:

sudo diskutil umountDisk /dev/disk3
sudo dd bs=1m if=/dev/disk3 of=~/Desktop/raspbian-stretch-lite.img