JohnKlann / Uncategorized

List Files with their absolute path using Bash

function lsfp(){
local dirpath="$1"
local recurse="$2"

if [[ "$dirpath" == "" ]]; then
echo "no path provided!"
local dirpath=$(echo "$dirpath" | sed 's:/$::g')

local DirArr=($(ls -l "$dirpath" | grep -P "^d" | grep -oP "(?<= \d\d\:\d\d ).*"))
local FileArr=($(ls -l $dirpath | grep -oP "(?<= \d\d\:\d\d ).*$"))

for file in "${FileArr[@]}"; do
local fp="$dirpath/$file"
echo "$fp"

if [[ "$recurse" != "" ]]; then
for direc in "${DirArr[@]}"; do
lsfp "$dirpath/$direc" "$recurse"

Start Powershell as Administrator in a Specific Directory

This is a continuation of a previous post on starting a process in powershell as administrator. QT Powershell #4

In this post the focus will be on lunching powershell as administrator to a specific directory.

  1. Open windows run prompt (win+R)
  2. Enter following command:
    1. powershell start-process powershell -verb runas -ArgumentList “{-NoExit -Command cd c:\tmp | clear}”
  3. In this case it will run Powershell as admin and change directory to my c:\tmp directory then clear the new shell.

Now I know that is probably is the most convenient thing way of doing this, so if you normally want to get to the same directory we can speed up the process by taking advantage of a windows shortcut.

  1. Go to your desktop or where ever you want to store your shortcut then right click > new > shortcut.
  2. In the “Type the location of the item:” field enter powershell. Then click Through the rest of the prompts.
  3. Next right click on your new shortcut and select properties.
  4. In the Target field of the “Shortcut tab” delete everything in it and paste your powershell start command (ex see previous step 2.1)
  5. Now for the most convenient part in the “Shortcut Key” field press a hotkey combination that you would like to use to execute the powershell command.
    1. ex: Ctrl+Alt+P
  6. Finally in the “Run” field use the drop down menu and select “minimized”, then apply ok.

Now you can just press your hotkey and boom you have powershell as admin in a specific directory.


Easily Manage a Service on a Remote Machine

For this example I will use Windows Remote Desktop Services and their ever needing service restart.

  1. Remote Restart Service
    1. Syntax
    2. Get-Service -ComputerName yourremotecomputername -Name servicename | Restart-Service
    3. Example (Restart Remote Desktop Services)
    4. Get-Service -ComputerName server1.domain.local -Name TermService | Restart-Service -Force
    5. The “-Force” is added to the end as TermSerivce has dependent services and this flag is required to restart TermSerivce as well as its depedencies
  2. From here you can explore other Service commands and options using this base syntax to get the service object on a remote machine.



How to display HTML code in an adobe flex desktop application the Easy Way

So am very new to adobe flex and really don’t plan on using it that much other than to generate a quick ui for something simple.

In this case I wanted to use flex to create a small desktop app to load a live monitor website. In this case the default <mx:HTML location=”” was not loading the site at all so was digging all over the place for a solution. I came across expensive libraries that could do it, and a pretty cool github project called Flex-iFrame if you want to get complicated with it. Needless to say I came up with my own solution.

The idea is that the <mx:HTML location=”  can point to a location html file as well. So I wrote a quick html page with an iframe to the website I wanted to monitor. Next I copied the html file to the /src/ directory of the adobe flex project folder.  Finally I added the line <mx:HTML location=”myhtmlfile.html” /> . This worked great for my application and seems to be the easiest way to perform this process.


1.)  Create your adobe flex project:



2.)  Name the projected whatever you want and be sure to select the Application type as Desktop then select finish:



3.)  Next create the html file with the html you want to display in my case an iframe:

<iframe src=” height=”400px”></ifram>

Note:  you can add jquery and css file links as well if they are local to your system make sure you copy them with the html file in the next step.

4.)  Now that you have created the html file copy it and any other dependent files to your flex projects src directory. Typically the path will be something like:

C:\users\username\adobe flash builder 4.7\ProjectName\src

Note: This is also the directory where the projects  .mxml and  -app.xml  will be located.

5.) The last part for this will be to add the flex html location code to view the file add something like the following to your flex project.

<mx:HTML location=”yourhtmlfile.html” />





Note: From  here you can build the rest of your app and style it the way you would like.

6.) Finally run your app!




port forward config router

How to: Setup Port Forwarding For SSH

Port forwarding will allow you to connect to your SSH server from anywhere, and it is really easy to do.


Administrator access to your router
Putty client

Step 1: Login to router

Login to your router via a web browser using its IP address (default is

router browser login

Next you locate where you can setup port forwarding. In my case it is under  Applications & Gaming sub tab Single Port Forwarding.

Once located create a custom forward with the following settings:

Internal port: 22
IP address of your SSH server.

Save the settings.

port forward config router

Step 2: Get your external IP address

You can find your external IP address by visiting

 *Note: Unless you have a static IP provisioned by your ISP, your external IP address will most likely change often. There are several services that allow you to track the change, and assign a domain name to it (Never had much luck with them). I went with a much more simple approach. View the article here.

Step 3: Creating your first external connection

From computer outside your LAN open your putty client.
Enter your external IP address into the Hosts field and click open.

putty setup ext ssh session
If you receive a popup box like the following select yes to continue:

rsa key working ssh
Enter your username and password:

ssh login
Then you will receive a shell on the SSH server:

secure shell on remote ssh server

Related Articles:


How to: Setup a SSH Server on Windows

This How to will walkthrough the steps to setting up an free ssh server on Windows operating systems. The will allow ssh access (secure shell access) to windows command prompt, and provide you with the ability to utilize other tools like Putty(tunneling), and WinSCP(file transfers). This walk through will show you how to set this up within your LAN (Local Area Network).


SSH server software — For the use of this tutorial, freesshd will be used.
Putty client — ssh client

Step 1: Install freesshd

freesshd installer

Step 2: Configure freesshd

Once you have finished installing the ssh server, run the application. You will want to edit the settings:

Right click on the freesshd icon in the taskbar and select settings

freesshd taskbar settings

You may see that the ssh server is not running and it may not start when you attempt to start it. Do not fret your machine probably needs a reboot. However ever this can wait until after the configuration has finished. For the next steps we want the SSH server to be stopped.

freesshd server status

Most of the defaults are effective there is only one last thing to configure.

Select the Users tab and click add user:

freesshd add user

Add your windows user account name under login. If you are not attached to a domain just leave the domain field blank.
Then select the user permissions. (personally I selected them all.)
Select ok.

Now start your SSH server on the Server status tab. Reminder if it will not start remember to reboot your machine and try to start it again.

Step 3: Create your first SSH session.

Collect you computers ip address:
Press windows key + r.
Type cmd into the run dialogue box and hit enter.

run dialogue command prompt

In the command prompt type ipconfig and press enter. Your ip address will be listed under your adapter.

finding your ip address cmd ipconfig

From another computer on your LAN (local area network) download and run the putty client.

Type in your ip address of the SSH server then select open

putty setup for simple ssh session to windows

This will then prompt you for your user name and password. *Note: it will show nothing when you type your password in. Once complete this will open a Command Prompt Shell on the remote system.

ssh windows command prompt shell

Related articles:

How to transfer files to and from a windows server using ssh with WinSCP

How to setup port forwarding for ssh


Python: How to get external IP address

Here is a short simple way to get the external ip address of a machine using python. This of course is useful if your machine is sitting behind a router or a sub network. So unfortunately there is no one liner in python to grab your external ip address which means a third party service must be used. However you can be your own “third party” service if you own a website. (If you don’t you can always use mine!)

Step 1:

Create a php file called getmyip.php you will want to include the following code:


$ipaddress = $_SERVER["REMOTE_ADDR"];

Echo "Your IP is $ipaddress!";


Upload this to your website and mark the location.

Step 2:

Create a python file called you will want to include the following code:

import urllib

import re

def get_external_ip():
site = urllib.urlopen("").read() #if you want to use my website the url is:
ip=re.findall(r'[0-9]+(?:\.[0-9]+){3}', site)
address = ip[0]
print address
return address


Then just execute the python script.

You can find the source here


Vmware does not see an external usb device, wifi, drives, ect…

So recently I build all new machines. I specifically build a machine with tons of resources for all of my virtual machines. So naturally the first operating system I install in Vmware is Backtrack 5 R3 Gnome. I was excited to begin pentesting on my newly allocated machine. I wanted to start with a basic WiFi cracking test, to see how the machine handled the resources provided. I attached the USB WiFi card and realized that I could easily use it in windows, however when attempting to add it to the virtual machine, Vmware was not even recognizing it. I searched all over, and only found forum post and simple tech docs from Vmware explaining how to drop down the “VM” menu and select the device from the removable devices. Nothing mentioned how to added the device if Vmware was not even seeing it.

After a minute of refection on how I setup the Vm I remembered that it provided an option to use USB 3.0 devices, which I had selected. I removed the device from my USB 3.0 ports and moved it back to a regular USB 2.0 port and Vmware immediately found the device and attached it to the VM.

If you perform a simple search from google you will find that this a known issue that is “not yet fixed”

Google Search

Vmware Article / Tech docs

VmWare Technical Support Documentation

Their “Solution” more like work around is to use a USB 2.0 or 1.1 port.

My system Setup (if you would like to compare for troubleshooting issues)

OS Name Microsoft Windows 7 Home Premium
OS Manufacturer Microsoft Corporation
System Manufacturer System manufacturer
System Model System Product Name
System Type x64-based PC
Processor AMD A8-3870 APU with Radeon(tm) HD Graphics, 3000 Mhz, 4 Core(s), 4 Logical Processor(s)
Boot Device \Device\HarddiskVolume1
Hardware Abstraction Layer Version = “6.1.7601.17514”
Installed Physical Memory (RAM) 32.0 GB
Total Physical Memory 16.0 GB
Available Physical Memory 12.4 GB
Total Virtual Memory 32.0 GB
Available Virtual Memory 27.9 GB
Page File Space 16.0 GB

Vmware Workstation 9 completely up to date.

I will keep everyone posted as I know more.


How to Stream a Webcam through SSH with VLC on Backtrack 5 R3 Gnome 32


You will want to perform Steps 1 and 2 on both the server and the client.
Step 1: Install VLC and Fix it for Backtrack 5 

apt-get install vlc

hexedit /usr/bin/vlc

Press tab

replace geteuid._libc_start_main with getppid._libc_start_main



vlc “and it should now work”

Step 2: Setting up ssh “if you have never used it”

nano /etc/ssh/sshd_config

Add the following Lines or un-comment them if they are already there.

PermitRootLogin yes
UsePrivilegeSeparation yes

X11Forwarding yes
X11DisplayOffset 10
TCPKeepAlive yes

UsePAM yes

If you have not used ssh before you will need to generate keys run commands below:

Enter file in which to save the key (/root/.ssh/id_rsa):

Enter file in which to save the key (/root/.ssh/id_rsa):

Step 3: Now you will need to start ssh by running the command below:

start ssh

Step 4: Now that everything is setup lets start the webcam stream:

ssh -C -X root@serverip -L 9091:localhost:9091
“backtrack’s default is: toor”

Note: If you get an error about the SSH keys not matching.

gedit /root/.ssh/known_hosts

Then delete everything and save the file.

Then run the command below:

vlc v4l2:// :v4l2-dev=/dev/video0 :v4l2-adev=/dev/dsp :v4l2-standard=0 :sout="#transcode{vcodec=mp4v,vb=800,scale=1,acodec=mpga,ab=128, channels=2}:duplicate{dst=std{access=http,mux=ts,dst=localhost:9091}}"

Now open a new terminal and run this command:

vlc http://localhost:9091