Tuesday, March 21, 2017

i3WM: Populate Workspace with Terminals

I recently wrote a script to populate a workspace with four terminals in i3 Window Manager, each taking up a quadrant of the screen.


populate i3 window manager with terminals in quadrants
Four Terminals



This script is nice because I often find myself needing multiple terminals and this saves a little bit of time by automating the process. The bash script is as follows:


#Written By Brian Winkler
#Free to use and distribute
#!/bin/bash

exec xterm &

sleep 0.3

i3-msg 'split h' &&

exec xterm &
sleep 0.3

i3-msg 'split v' &&

exec xterm &
sleep 0.3

i3-msg 'focus left' &&
i3-msg 'split v' &&
exec xterm &

exit 0

As you can see, its a simple script. I had to play around with the sleep time a bit in order to get the terminals to open in the correct configuration. '0.2' for the sleep value works about half the time, depending on the system load. I chose to go with '0.3' since it ended up being more reliable, though does has a noticeable lag.  You win some and you lose some.

To use this script, I place an executable version of the script in '/usr/local/bin' and named it 'terms'. This way, I can call this script from dmenu use it whenever I need to populate a work-space with terminals.

Well, that's all for now! I hope you find this script useful. Please free to comment or ask questions or tell me how inept I am!





StumbleUpon

Tuesday, January 24, 2017

Wayland on GNOME: Update 1

As it currently stands, I cannot get steam games to run under Wayland. I had to revert to the X server to play steam games.

I also cannot get VLC player to work, but I think that may be my own incompetency more than the fault of Wayland.

Otherwise, everything is still running very smoothly. I've noticed a slight increase in battery life but not enough to attempt to quantify it. Windows are still smooth but my cursor speed suddenly feels slower, though I haven't altered any settings. This just may be a perception relative to how much faster everything else is now.

That is all.


StumbleUpon

Wednesday, January 18, 2017

Part 2 - Poisontap: Setting up the device

This post is a continuation of my guide for setting up Poisontap. You can read more about Poisontap here and you can read my previous post regarding Poisontap here.

Part 2 will cover the set up of Poisontap on the Raspberry Pi Zero along with a short review outlining my thoughts on the program itself. This guide uses Raspbian Jessie Lite for the Pi operating system. I also utilized an USB serial cable but this can easily be worked around.

You will need:
-USB Serial Cable
-Raspberry Pi Zero
-Micro USB to Female USB 2.0 or 3.0
-Wifi Dongle

1. Preparing the Device
The biggest problem I ran into regarding getting Poisontap set up on the Pi was the lack of internet access on the device. You can purchase an adapter to be able to attach a USB Wifi dongle or Ethernet cable but the method I used was to be able to use the internet on my Arch laptop via Micro USB cable. Contact me if you want more details on this. For the purpose of this guide, I will assume you managed to connect a wifi dongle to the RPi and have internet access that way.

The first step is to enable the Ethernet on the RPi. I did this through accessing the MicroSD card on my laptop via an SD card reader.

In '/boot/config.txt', add the following line at the end of the file:


dtoverlay=dwc2

Then, in '/boot/cmdline.txt' add the following line after 'rootwait':


modules-load=dwc2,g_ether

Now, you will want to change the network settings to have the Pi act like an Ethernet connection over USB. Depending on the way you configure your internet connection on the Pi, you may want to leave this step for last, as in skip it and come back to it. DO NOT SKIP IT ENTIRELY. On the Pi, in '/etc/network/interfaces', add the following lines:


auto usb0
allow-hotplug usb0
iface usb0 inet static
     address 1.0.0.1
     netmask 0.0.0.0




2. Downloading PoisonTap

If you haven't already installed 'git' on the Pi, you will want to install it now. Then run:


git clone https://github.com/samyk/poisontap.git

Move to the downloaded directory and edit the configuration files to point at the back-end server you set up previously.

Once that's done, you'll want to add the PoisonTap script to '/etc/rc.local' on the Pi:


/bin/sh /home/pi/poisontap/pi_startup.sh &

Make sure to place this before 'exit 0'. Finally, install the following packages to allow PoisonTap to run properly and update the Pi to make sure all other packages are up to date:


sudo apt-get update && sudo apt-get upgrade && sudo apt-get install -y isc-dhcp-server dsniff screen nodejs

And there you have it! You should now have set up PoisonTap successfully on the Raspberry Pi Zero!

3. My Thoughts

Honestly, I'm rather unimpressed with the way PoisonTap operates. It does operate as advertised but I think the buzz surrounding it made me have unrealistic expectations for it.

As soon as I plugged the device into my test machine (my personal laptop), Chromium jumped into lock-down mode, not allowing for any traffic other than HTTPS. I managed to get be able to download browser data once I used Vivaldi as the browser but I still couldn't get any of the remote features to work. I do pride myself on running a tight ship when it comes to the security of my computer and I am completely unwilling to remove settings on this machine in order get this to work. It seems counter-intuitive to me. My goal was to end up with a device that can reliably gain access to machines and I don't feel like that's what I ended up with. This may be different under Windows but I don't have access to a Windows machine so I couldn't tell you.

Overall, if I had to rate this project as a flavor of ice cream, I would go with vanilla. It's good enough as so I'm not entirely disappointed but it certainly leaves room to be more impressive. The biggest take-away from this project was getting the RPi to function as an Ethernet device, which opens the door for future exploits and projects, but if you're hoping to have this 'wild and crazy' hacking device everyone has been describing, you're looking in the wrong place.



StumbleUpon

Wayland on GNOME

I'm gonna keep this one short.

Due to the death of the Infinality patchset, I switched from Plasma 5 back to GNOME 3.22.2 before I connected Infinality's death with the general mucking up of my system. Plasma 5 along with various applications would fail, returning the message that the 'harfbuzz.so' binary could not be loaded. Once I was deep into re-configuring my system (I did a fresh install of Arch and I'm giving Butter FS a whirl) and couldn't seem to stop replacing different components of my usual set-up. This led me to replacing X11 with Wayland (since I was in the neighborhood) and I have to say, I'm rather impressed.

The first thing I noticed was an improved overall responsiveness. Animations and window movement both are much smoother; It feels less like my system is struggling to keep up with me and more like it's predicting my next move. I also lost a little less than 100MB from my system's idle RAM usage. I gained about 3 seconds in my desktop environment load time giving me an average of about 20 seconds from boot to a usable GUI.

(Related tip: If you're using GNOME shell extensions, don't use the Applications Menu or the Places Status Indicator extensions, they added a solid 10 seconds to the loading of 'gnome-session' from X on my system.)

It was enough improvement to give me the confidence to use an animated wallpaper, this one here. Its only been a few hours but I haven't noticed any decrease in performance, though it it eating up around 50MB of RAM (for a net gain of ~50MB).

An interesting change has been the touch pad. Wayland employs 'libinput' over 'synaptics' for the touch pad driver and the support for 'libinput' in desktop environments is still in the works. Currently, the two ways to configure 'libinput' are through your desktop environment settings and through the 'libinput-gestures' package, available in the AUR. I found most of the settings for 'libinput-gestures' to be touchy so I stuck with three finger swipe (left/right) to go forward and backward in my browser and four finger swipe (left/right) to step through open tabs. Generally I've found this experience to be smooth with few hang ups.

The way the cursor moves is also different. I'm not sure how to explain it or if I can even assess whether I like it better or not. Its one of those things you'll have to see for yourself.

A definite draw-back is that with GNOME, there is no scroll coasting under Wayland nor is there two finger horizontal scroll. Both of those where previously handled by synaptics and libinput is yet to implement support for them.

Overall, I'd recommend giving Wayland a shot and seeing how you fare.

StumbleUpon

Tuesday, November 29, 2016

Part 1 - PoisonTap: Setting up the backend

This is the first in a series on how to set up PoisonTap, by Samy Kamar.
Poison Tap, a USB device that costs no more than $5, can hack into web browser cookies and other parts of any computer just by being plugged into a spare USB port, claims Samy Kamkar, the developer of the USB device. Kamkar built the device out of a Raspberry Pi microcomputer. [Source] 

This guide will cover setting up the backend server, which the Raspberry Pi communicates with to transmit data back to the attacker. This guide assumes you're familiar with using ssh along with being comfortable editing some text files.

1. Setting up a VPS

In order to run PoisonTap, you will need a server for the device to communicate with once it infiltrates the target device. In this guide, I'm using Digital Ocean to host the server. Thanks to the folks over at Jupiter Broadcasting, you can use the promo code "heresthething" to get a $10 credit toward your account which can be used for two free months of service.

Once you're signed up, follow Digital Ocean's easy-to-use interface to deploy an Ubuntu 14.04 x64 server with Node.js pre-installed. They will email you your ssh password and use this to log into the server. Once you're in the server, run the command:

apt-get update && apt-get install nginx git

Note: For the purpose of this guide, all commands must be run as root.

This will install nginx and git along with updating the package list.

2. Setting up nginx

The first thing you'll need to do is set up nginx. Create a new file called 'nginx.conf' in '/etc/nginx/conf.d/' and add the following code to it:


server {
    listen 80;

    server_name brighbox.tk;

    root /usr/share/nginx/html/node;
    index index.html index.htm;

    client_max_body_size 10G;

    location / {
        proxy_pass http://localhost:1337;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_buffering off;
    }
}

The post 1337 can be changed to any port but by changing the port, you will need to edit various config files which I'll go over later.

Then, run the following command to ensure that pm2 is installed on your VPS:


npm install pm2 -g

3. Launching the node.js application

Now that you're all set up, head over to Samy Kamar's github to download PoisonTap, or pull it using git by running the command:

git clone https://github.com/samyk/poisontap.git

Then, change your working directory to the poisontap directory:


cd poisontap

Once in the working directory, we can check that the .js application will run properly by running:


node backend_server.js

If any errors are thrown here, do not fret. There is excellent documentation available regarding node.js and Digital Ocean. You can find this information here.

Once the node.js application is running correctly, you can launch it by running:


pm2 start backend_server.js

Then, you'll need to restart the nginx service:


service nginx restart

And finally, you can make sure that the application is running using the command:


pm2 list

You should see the following:

Expected output from the pm2 list command
pm2 list

And there you have it! Now the backend server for PoisonTap is set up and you're ready to set up your Raspberry Pi Zero to communicate with it! Stay tuned for my guide on setting up the Raspberry Pi Zero with PoisonTap. Please feel free to leave any comments or ask any questions, I'm more than happy to help folks out.

Notes:

The first thing to realize is that it is a Federal crime in the United States to gain unapproved access to digital media. This guide exists for educational purposes only. If you choose to disregard this warning, know that the services running on a target computer will point to your Digital Ocean server, making it very easy for someone to track you down, probably resulting in jail time. Use at your own risk!



StumbleUpon

Wednesday, September 28, 2016

Refined brightness with i3-WM and i3blocks

I'm a picky person and it decided it was high time to clean up the display for my brightness in i3blocks.


In order to control my brightness via the keyboard, I found that I needed to create a bindsym using xbacklight to reflect this in my ~/.config/i3/config. I chose to increase and decrease xbacklight by 10%.

Initial bindsym:


#Brightness controls
bindsym XF86MonBrightnessUp exec "xbacklight -inc 10 ; pkill -RTMIN+1 i3blocks"
bindsym XF86MonBrightnessDown exec "xbacklight -dec 10 ; pkill -RTMIN+1 i3blocks"


The problem I found with this is that xbacklight increases and decreases based on percentage values of the total maximum brightness for the screen, which on my system is 937. This meant that if i3blocks displayed my brightness at 100% and then I decreased it by 10%, the next value displayed was 89%. This bothered me for no other reason than I am pretty neurotic.

The other problem is that at night-time, I wanted to be able to easily set my brightness to just slightly above 0% to reduce strain on my eyes while using my laptop in total darkness. I also wanted to be able to turn my screen off using the brightness controls because my partner enjoys listening to netflix shows with the screen off while she's trying to sleep. At the settings I had initially, I could turn the screen off but once I increased the brightness, it increased to a value of 9, which is too bright for an initial value in my opinion. To solve this, I wrote two bash scripts to handle the brightness and ensure the output of multiples of ten.

To increase screen brightness:


#!/bin/bash
#Created by Brian Winkler

#This script is free to use and modify as your own

#Check out my blog at https://nuxview.blogspot.com/


STATUS="$(xbacklight -get)"
CHECK="${STATUS}"

if [[ $CHECK == 0.000000 ]]

then
 xbacklight -inc 1
 pkill -RTMIN+1 i3blocks

else
 xbacklight -inc 10
 pkill -RTMIN+1 i3blocks
fi


This script checks if the brightness value is at its lowest and if it is, increases the brightness by a value of 1. Otherwise, it increases the brightness by a value of 10.


To decrease screen brightness:


#!/bin/bash
#Created by Brian Winkler
#This script is free to use and modify as your own
#Check out my blog at https://nuxview.blogspot.com/

STATUS="$(xbacklight -get)"
CHECK="${STATUS}"

if [[ $CHECK == 100.000000 ]]

then
 xbacklight -dec 9
 pkill -RTMIN+1 i3blocks

else
 xbacklight -dec 10
 pkill -RTMIN+1 i3blocks
fi

This script checks if the brightness is all the way up and if it is, decreases it by a value of 9. Otherwise, it decreases the brightness by a value of 10.


For both of these scripts, pkill -RTMIN+1 i3blocks makes it so I can set my interval to once in the brightness display command in i3blocks.conf and then whenever I change the brightness, it automatically reloads the brightness display.


So now my i3blocks brightness block is using only multiples of ten and allows for me to turn my brightness off and when I turn it on, it first sets the brightness to the lowest possible value.

I then made these scripts executable using chmod +x and copied them to /usr/local/bin/ and named them brightinc and brightdec respectively.


My new ~/.config/i3/config looks like this:


#Brightness controls
bindsym XF86MonBrightnessUp exec brightinc
bindsym XF86MonBrightnessDown exec brightdec


These scripts as also available on my i3blocks github.


If you have any questions or comments, please feel free to contact me or to comment here. I would love to hear from you!










StumbleUpon

Monday, September 12, 2016

Create Linux users using a C program

Today, in order to further familiarize myself with C programming, I wrote a program to automate the process of creating new users. This program is for personal use only, meaning if you are running this on a server with many users, you run the risk of something being passed to the program that can harm your system.

Here's the source code:


#include <stdio.h>
#include <stdlib.h>

//Created by Brian Winkler
//Create new user

int main (void) {
        char user[128];
        char add[128];
        
        
        printf("Enter a user name:\n");
        scanf("%s", user);
        
        snprintf(add, sizeof(add), "useradd -m -G users -s /bin/bash %s", user);
        system(add);

        printf("User %s created!\n", user);
        return 0;
    
    
}

It's a very simple program but through compounding Linux commands, a very powerful program can be created. This program has been tested on Arch Linux and Ubuntu 14.04.

This source code can also be found on my github.



StumbleUpon