Today I wanted to write a quick tutorial on using github and some of the issues I encountered. I wanted to perform a really simple task but help pages on the github site were confusing and overall pretty useless.
So what did I want to do?
I wanted to get involved with the BeEF project (https://github.com/beefproject/beef/wiki). I had worked on improving the Pretty Theft module and thought I would submit my work to see if anyone was interested in it. Sounds simple enough right? Hmmm... :)
Github is essentially a sourcecode repository and project collaboration site. It's great for open source projects as users can download the source, modify it and then submit their changes. If the original author likes the changes they keep the new version and the project gets better and better over time thanks to user submissions.
How do you download code from github?
Create an account at www.github.com, go to the project page your interested in and press the "Fork" button in the top right of the screen. That will create a copy of the code for your own personal use. To actually start editing the code I switched over to my Backtrack 5 (BT5R3) machine and downloaded the code with the command:
git clone https://github.com/pwndizzle/beef.git
The address for your fork should be on your forked page on github. For me my user account was pwndizzle and the beef.git is the source for the beef project. BT5R3 already has git installed so you should have no trouble with this command.
How to update git in BT5? How to change repositories in BT5?
Although BT5R3 has git installed it is not the latest version. Running the command "git --version" I get the version 18.104.22.168 and even after an "apt-get install git-core" I was not able to get the latest version. Why is this an issue you might ask? Well later, when trying to upload to github, I was getting the error:
Error: The requested URL returned error: 403 while accessing # https://github.com/user/repo.git/info/refs # fatal: HTTP request failed
This link has more info: https://help.github.com/articles/https-cloning-errors
To address this issue I managed to update git by adding the ubuntu repositories to /etc/apt/sources.list and then performing an "apt-get update" followed by "apt-get install git-core". I added the following repositories to the source.list file:
deb http://archive.ubuntu.com/ubuntu/ precise main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ precise main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ precise-updates main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ precise-updates main restricted universe multiverse
The command "git --version" should now show up as 22.214.171.124 and we won't get upload errors later on.
How to upload files to github?
Once you have locally edited some of the files in the clone you'll want to upload them to github. First I set my username that would be used when submitting files:
git config --global user.name "pwndizzle"
I was then ready to push my changes to the github website. This is a three stage process, first you choose what files you would like to include using the add command, you confirm using the commit command and then finally upload the changes to github with git push. To find out the current state of your clone you can use the "git status" command at any time from within your local clone folder.
Here are the commands:
git add /yourpath/yourfile1
git add /yourpath/yourfile2
git commit -m "Add your message here, e.g. Updating files 1 and 2"
git push origin master
The changes I had made on my machine were now incorporated into my fork on the github site and I was able to share these changes with others. The final question is how do you send the original author your changes? Go to your fork page and click "Pull Request", fill in the forms and submit. Done!
Next post I'll be talking about my work with BeEF :)