Just to say I don’t condone by passing firewalls but if needs must to get a job done heres how.

So we’ve all worked in places with restrictive firewalls that make our life as admins difficult. Its easy enough to tunnel out of most firewalls if you have a SSH server on the outside you can even set it to run on port 443 if you can’t get out on 22, you can then use a dynamic tunnel using the -D flag for SSH to bounce outside the restrictions. But what if you need to do something a bit extra? What if you need to access your desktop machine from outside of your network but the VPN solution your company supplies doesn’t deliver? Well SSH can be your friend here too. Reverse SSH tunnels are going to get you right into the heart of the corporate network and probably expose how lax the security really is where you work ;) but hey if you’ve got a job to do this will just let you get on with it.

Firstly you’re going to need to initiate this from your corporate desktop in advance, you’re also going to need a “jump box” ssh server you can hit ont he internet, and finally you’ll need your local desktop.

From your corporate machine you need ssh running as a service here also then you need to make a SSH connection out to your jump box but allow connections back in down that SSH connection you’ve just opened. Its easier than it sounds:

On the corporate machine:

ssh -R 2100:localhost:22 <USER>@<YOUR_JUMP_BOX>

This opens an SSH connection to you jump box and sets up port 2100 on the jump box to forward back down the tunnel to your corporate machine on port 22.

Now for the funky stuff. You want to use your local desktop browser to surf the web but appear as if you are in the office IP range. So lets first connect to the jump box from the local desktop and open a new normal SSH tunnel:

On your local desktop outside the network:

ssh -L 8080:127.0.0.1:2101 <USER>@<YOUR_JUMP_BOX>

Don’t worry if you get erros like the following, its purely because we haven’t connected the two tunnels to each other:

channel 3: open failed: connect failed: Connection refused
channel 4: open failed: connect failed: Connection refused

Ok now time to connect to two SSH tunnels together. On your newly created SSH connection as shown above type the following in to the shell of the jump box:

On the jump box:

ssh -p 2100 -D 2101 localhost

This not only joins your dynamic tunnel to your reverse tunnel and ssh’s into the corporate machine but also allows HTTP traffic to flow between the local desktop and corporate machine using a socks proxy! Your local desktop forward traffic on port 8080 to the jump box which in turn forwards it to the jump box (localhost) onto port 2101. Now port 2101 is forwarded down the reverse tunnel to your corporate machine and you can browse the web.

Now all thats left to do is tell your browser on your local desktop to use a proxy and the details will be localhost port 8080 and the type is socks 5. Now you can browse the web as if you’re in the office and access local intranets but also you have a shell open to your desktop to do some work that can be only completed from inside.

I hope you all find this useful, and no doubt you’ll be able to forward all kind sof traffic in a simular way!

, , , ,

Hi all,

Just a quick post to announce the availability of a nodeJS PPA repository for Ubuntu 12.04. This PPA currently supports nodeJS 0.6.11 and npm 1.1.1-7 but I’ll be aiming to update as the new stable releases come out. Hopefully this will enable more of you to work with the current stable release of nodeJS instead of the ubuntu/debian default which at the time of writing is on the 0.4.x branch.

You can read more about the repository here:

https://launchpad.net/~richarvey/+archive/nodejs

or easily add the repo by running this from the command prompt:

sudo add-apt-repository ppa:richarvey/nodejs

For those of you wishing to know more about nodejs hop on over to http://nodejs.org

, , ,

A Quick VIM Primer

When you read a lot of HOWTO’s and guides for Linux you’ll often find commands that say edit a file in vi or vim. However we (old skool admins) tend to forget how infuriating these editors can be for new users, so here a little primer that will hopefully get you going. Vim is extremely powerful and is normally installed either as vi or vim on most systems, its lightweight and quick to edit a file remotely on your server for example.

Getting Ready.

First of all lets get you using vim (Vi improved) rather than vi. from a terminal run:

sudo apt-get install vim vim-scripts

vim-scripts isn’t needed but I’ll touch on some articles about using them at a later date.

Now lets make vim your default terminal editor.

update-alternatives –config editor

Select the option /usr/bin/vim.basic

Basics.

Ok now lets create and work on a file. Run:

vi testfile.txt

You’re now faced with a blank screen, and at present no way of entering text. BEFORE pressing anything else press insert, you’ll notice “testfile.txt” [New File] changes to — Insert –. If you press insert again it will say — Replace –. These are the main edit modes we’ll cover in this primer, I’m sure you can work out the difference between insert and replace.

So now you can start typing. As you can see its very basic, but that’s all yo need to edit most files.

Now lets say you want to save your work. Firstly we must exit insert mode. To do this press Esc. The line which once said — Insert — is now blank. To enter any command in order to make vim do things like save and exit you need to use the colons : As you press this you’ll see it appear in the bottom left hand corner. To save your work type w (short for write) followed by enter. The status bar at the updates to tell you the file is written. Now if you want to edit the file simply press insert again!

To exit vim completely press Esc to get out of editor mode followed by : then q (short for quit) followed by enter. NOTE: this will not save changes you make to the file. To save and quit use Esc :wq followed by enter.

If you’ve opened a file edited it then decided its now not what you want to do, vim wont let you exit the file before saving. To over come this use ! to force a command. Esc :q! then enter means quit and don’t worry about prompting me to save.

Quick deleting.

Now lets do some more advanced stuff. Image you just need to open a file and delete a section. For this you don’t even need to go into editor mode (– Insert –). Lets try this by working on your file. Make sure you have a couple of lines of text, separate lines would be even better. Now exit edit mode by pressing Esc. You notice you can still move the cursor around on the text but you can’t actually go right to the end of a line and start typing new text. Move your cursor to the beginning of some text you want to delete and press x. Yes you can see it deleted the letters from in front (to the right) of the cursor. Now that’s great for quickly deleting a few bits then saving the file and exiting. But what if you want to delete a complete line? Simple move your cursor to that line and press d twice. Bang its gone!

Copy/Paste.

You can always highlight text from anywhere by just left click on the mouse and dragging as per normal, but if you’re new to Linux, you may not know that you can then just simply paste by middle clicking in the new document. You can use these features in the terminal also. However vim offers a few tricks of its own. For example lets say you want to duplicate a line of text already in your document and move it else where. Make sure you are NOT in editor mode, move the cursor to the line you want to copy and press Y (short for yank also note its a capital). Now move the cursor to somewhere else in the document and press p. Your line gets pasted. Now use this with the delete command and you can move text round your document easily. Also you’ll find if you delete a line using dd you can then paste it somewhere else using p.

Stacking up commands.

Now you know how to Yank and Delete lines, what if you want to do more than one line? Simple before your command type a number. For example 2dd will delete two lines. 5Y will copy five lines. Give this a go as it will get you used to the concept that vim is very flexible with its commands.

Syntax and line numbers and strange pasting.

Lets say you’re editing a .php file. Vim can highlight the code and show you incorrect syntax or even make it easier to see the start and end of {} or <>. To turn this feature on type Esc :syntax on then press enter and the magic will happen. You may also want line numbers just type Esc :set number on. You can of course turn these off by swaping on for off in the previous commands. If you find when you paste some text from a website it goes haywire when inserted into vim turn off AI which tries to work out what the indentation should be Esc :set noai

A good trick is to switch these features to be always on, to do this create a file in your home directory called .vimrc

vi .vimrc

add these lines

syntax on

set number on

set noai

Now exit vim and open a .php file. You’ll see the features are automatically turned on.

Search and Replace.

I use this command a lot! Its incredibly handy for editing config files. This is fairly advanced for this primer but as I use it so much I though you’d find it useful also. I’ll start by just showing you the command and then breaking it down. Yet again start by leaving insert mode, by pressing Esc.

:1,$ s/foobar/moo/g

Lets break this down so it doesn’t look so confusing.

: – Colons as mentioned before precede any command.

1,$1 tells the command to start on the first line of the text (you could start on line 20 by just swapping this) you then need to follow that with a , and then you use the line where you want to stop this command running, so if you want to go to the end of the file use $ and vim works out this number automatically. However if you want to stop on line 30 and start on line 20 do something like this :20,30

s/ – is used to say swap anything matching the text after this line /

foobar – this is your first string so this should match the word you’re looking to replace.

/ – Separate the word you’re searching for with the new word.

moo – This is your new word.

/ – Tell the command that’s the end of the new word

optional g or ig means global this means every occurrence of the work in you file will be replaced (within your start and end line numbers) If you don’t use g you may find it only updates the first occurrence in each line. i will make the search case insensitive which can be useful. You can use both g and i together as so /gi

Hopefully this will help you start using vim and get confident with day to day tasks. There is MUCH more this editor can do, I recommend looking at The vim Cheat Sheet.

, , , , ,
You are protected by wp-dephorm:
Private