Sunday, February 12, 2017

Kali Linux on Android (Feb 2017)



So a few months back (Sept. 2016) I wrote a piece here about installing Kali Linux on an Android device. Unfortunately that guide is no longer valid, as Kali Sana the branch of Kali on which it was based has been deprecated and removed from the official repositories and is only available on backup repositories and is set to be removed from those too in the near future. So a new challenge appeared. The obvious route was to check if Linux Deploy's out of the box method was working this time. But again there were a few quirks prohibiting a smooth installation and execution. So this is an updated guide as of Feb. 2017 on how to install and lunch Kali Linux on an Android mobile device. You will notice that a lot of the steps are the same, that's because the base approach is the same it's a few details that had to be changed.

The Requirements

Preparation

  1. Partition the SD and format each partition (THIS WILL DELETE YOUR DATA). You'll need:
    • 1st Partition 512 MB formatted in FAT32
    • 2nd Partition the rest of the SD formatted in EXT2
  2.  Install the APPs listed above
  3. Open Link2SD
  4. You should be greeted by this screen

    1. Select ext2 and press ok
    2. When prompted reboot your device
  5. Open BusyBox
    1. Press INSALL 

    Installation

    1. Open Linux Deploy (From here on ensure constant Wifi connection and power)
      1. Press your phone's menu button
      2. Press status
      3. Under Available mount point there should be something like /data/sdext2, make note of that.
      4. Press the button on the right (looks like a download icon)
      5. In Distribution select Kali Linux
      6. In Distribution Suite select kali-rolling
      7. In Architecture select armhf
      8. In Installation type select Directory
      9. In Installation Path type in the path you took note of before
      10. (Optional)  Change Username & Password
      11. Set DNS server to 8.8.8.8 (Google's Public DNS server) since the default tends to fail
      12. Set Localization to en_US.UTF-8
      13. Under the Init Menu check enable
      14. Under Init System choose sysv
      15. Under SSH check enable
      16. Under SSH Settings > SSH options write the following
        1. ServerAliveInterval 15
        2. This will ensure the connection doesn't timeout during the installation of packets that can take up to hours.
      17. (Optional) Enable GUI options like VNC (won't get into it here)
      18. Press Menu > Install
      19. This might take a while ...
      20. When you see "<<<install" on Linux Deploy's logs the installation has finished
      21. Press Menu > Configure
      22. (If there was no error your system is now ready to boot).
      23. Here's where things change. DON'T PRESS START!
      24. Exit Linux Deploy by pressing the App's menu button and then Exit.
      25. Open Terminal Emulator
        1. su
        2. /data/data/ru.meefik.linuxdeploy/bin/linuxdeploy shell
        3. service ssh start
        4. exit
        5. exit
        6. This should Start Kali
      26. After every restart of the mobile device Kali has to start as demonstrated in the previous step (will provide automation script in following article)
      27. I have yet to find how to stop Kali without rebooting the device (which is what Linux Deploy does when you press stop). If anyone has any ideas feel free to drop a comment
    2. Now from ConnectBot ssh to yourusername@localhost
      1. sudo apt-get update
      2. sudo apt-get dist-upgrade
      3. (if prompted)
        sudo apt-get autoremove
      4. sudo apt-get install kali-linux-full
      5. PATIENCE, since this will download around 4GB of data
      6. The above is the most error prone part of the process. Ensure CONSTANT internet access and UNINTERRUPTED power to the mobile device. 
    3.  If everything went right you should now have a working setup of Kali Linux on your Android phone
    4. (Optional) If you don't need to SSH into you mobile's Kali from another device, consider limiting SSH access only from localhost.
    Hope this helps a few people skip a bit of the frustration. Have fun!

    Disclaimer: Make sure you understand what you are doing and follow the above AT YOUR OWN RISK. I had no problem during the above procedure, carried out multiple times on a couple devices, this isn't to say that problems cannot occur.

    Sunday, January 15, 2017

    How to change GitHub repo's preview image (sort of)

     Do you like having a photo of yourself as GitHub avatar but hate having it pop up as a preview when you post a repo on social media? Reed on!



    First things first, let me explain the "(sort of)" part o the title. Since there is no officially supported way from GitHub, at the time of writing, to achieve the desired result, the process described is a workaround, a hack, and thus entails a trade-off; you have to use a custom URL so anyone sharing directly the URL of your repo will get the original preview image.

    To achieve our goal we are going to utilize GitHub's project page generator that will generate a URL in the form : <username>.github.io/<repoName> (and this will be the link you will be sharing instead of the direct repo link that would be github.com/<username>/<repoName>). To better understand the process, we will see a general and an applied example in parallel. So in our case we will take one of my GitHub repos as an example github.com/panagiks/RSPET and the generated link will be panagiks.github.io/RSPET.

    GitHub's Project page generator

    GitHub provides a few ways to generate project pages, but for the purpose of this post we'll go with the gh-pages branch approach. First, create a new branch in your repo named "gh-pages" (no quotes) and empty it (delete all and any files that were at the source branch). Now create an empty file in the root of the newly created branch named "index.html". Now go to the repo's settings page and scroll down to the "GitHub Pages" section. There, in the "Source" section, you should see "gh-pages branch" selected in the drop-down menu, if not select it.

    Populating index.html

    The point is to create a webpage that will have the appropriate "meta" tags for social media to present it as if it was your GitHub repo, just changing the tags that correspond to the preview image. First make sure that you have uploaded the desired (new) preview image to a CDN (Content Distribution Network), I prefer Flikr for this because it's free and you can easily keep all your images in one place and also have them resized, but feel free to use any CDN you prefer the only thing that matters is that you have a URL pointing to the image. First is our example for github.com/panagiks/RSPET and following is the head section of the general index.html:

    In the body of index.html we only want it to redirect to the actual GitHub repo, to do that we do the following:



    Final Notes

    A helpful tool is Facebook's debug tool, from which you can see how Facebook will load and display your link as well as force its scrapper to rescrape your link. Finally, I intend to write a small script that will generate automatically the above "index.html" for any given GitHub repo, so stay tuned!
     

    Edit

    As promised, here's RGHPI, a script to automate the HTML generation step :)

    Friday, September 9, 2016

    Liked Elliot's one-tap command execution? Here you go!


    Did you like the way Elliot executed a PenTesting tool just by tapping a shortcut on his home screen? Well I'm going to show how to do this yourself. Now, there are a couple of ways this can be done, but the approach we're going to take here presumes you have a working installation of Kali Linux on your android. Without further delay, let's get to it!

    The Requirements

    1. A working installation of Kali Linux on your Android smartphone (as shown here)
    2. ConnectBot ssh client for Android
    3. Tasker for Android (Yes, I know, it costs 3)

    Preparation

    1. First we have to do away with the password requirement during ssh log-in
      1. To do that we will use ssh keys instead
      2. Open Linux Deploy (Make sure you have Kali's profile selected)
      3. Press "Start"
      4. Open ConnectBot
      5. Press your phone's menu button
      6. Select "Manage Pubkeys"
      7. You should see an empty screen (If you haven't already created another key, that is)
      8. Press your phone's menu button
      9. Select Generate
      10. Give a unique nickname to your key
      11. Select type and strength (I used RSA 4096bits)
      12. Leave the password blank
      13. Select "Load key in start"
      14. Now a key should appear in the previously empty screen
      15. Now we need to export the public key in order to provide it to the guest OS
      16. Long press on the key we just generated
      17. Select copy public key
      18. Now the public key is in the clipboard
      19. Go back and ssh into kali (with your password)
      20. Now in Kali run the following
        1. mkdir ~/.ssh
        2. nano ~/.ssh/authorized_keys
        3. Long press on the screen and paste the public key
        4. Send Ctrl+O 
          1. Tap once on the screen a small bar appears just above the keyboard
          2. On the far left there is a button that says ctrl, keep pressing that
          3. Press O from the on-screen keyboard
          4. You will be prompted for a file name just press enter
        5. Send Ctrl+X (the same way as Ctrl+O)
        6. sudo service ssh restart
        7. Press your phone's menu button
        8. Select Disconnect
    2. Second is the log-in automation and command execution
      1. On ConnectBot
      2. Type android@localhost in the field below and press Enter (this will create a new profile)
      3. You will be taken to the log-in prompt ignore it and go back to ConnectBot's main screen
      4. Long press on the profile that reads android@localhost
      5. Select Edit host
      6. In this example we will create a simple nmap execution
      7. So change the nickname to nmap (be careful to give each profile a unique nickname)
      8. Select Use pubkey authentication
      9. In the prompt select the key we created earlier
      10. Select Post-login automation (here you will write the commands the shortcut will execute)
      11. For our example 
        1. nmap 192.168.1.0/24
        2. Add a new line in the end (i.e. press Enter)
      12.  Press ok
      13. Now to test it go back to ConnectBot's main screen and tap on the profile named nmap
      14. If everything was done correctly it will log-in automatically and run an nmap scan on the 192.168.1.0/24 subnet
    3. And third is the home screen shortcut
      1. Open Tasker
      2. Go to the Tasks tab
      3. Press the + Sign
      4. Name your task (this name will show on the home screen) 
      5. In Task edit press the + sign 
      6. Select System
      7. Select send Intent
        1. Action : android.intent.action.VIEW
        2. Cat : Default
        3. Data : ssh://android@localhost/#nmap (in the position of nmap you put the ConnectBot profile you want to use each time)
        4. Target : Activity
      8. Go back to Task edit
      9. Press the play button (this will run the macro) 
      10. If everything was done correctly you will see ConnectBot opening logging into Kali and executing the nmap scan we set earlier
        1. If a prompt appears about what app to use select ConnectBot and press Always
      11. Go to your home screen
      12. Go to your add widget menu
      13. Select Task Shortcut
      14. Place the widget on the screen
      15. Tasker will open
      16. From Task Selection select nmap (or the task you want to add)
      17. Press the menu-like icon on the lower-right corner to select an icon
      18. Select the icon you prefer
      19. Press back
      20. You should now be able to see the icon you selected earlier on the screen
      21. Tap it
      22. If everything went well it will open ConnectBot log into Kali and execute the nmap command we set up earlier.

    Limitations/Considerations


    Unfortunately this method doesn't come without its flaws. For starters, Kali Linux has to be manually started through Linux Deploy (although it should be possible to make a one-tap task to automate that too so if anyone reading this has done it please leave a comment bellow). Secondly, if you close Tasker (not exit the interface, Close by selecting disable) tapping the shortcuts will do nothing so you will have to have Tasker running.

    Hope you found this guide helpful and easy to follow, if you have any suggestions/additions/corrections feel free to leave a comment bellow.

    Monday, September 5, 2016

    Installing Kali Linux on an Android smarthphone

    The problem

    In the time of writing a lot of the HOW-TOs available online, including Offensive Security's own guide, simply do not work. This post aims to guide anyone trying to install Kali Linux on his android smartphone.

    The Requirements

    • A ROOTED android smartphone (Tested on Android 4.4.4, MTK6752)
    • A 16 GB class 10 SD card (It should work with internal storage somehow but haven't tested)
    • Linux Deploy
    • BusyBox
    • Link2SD
    • (Optional) An ssh app (I used ConnectBot)
    • (Optional) A VNC viewer app (I used VNC Viewer

    Preparation

    1. Partition the SD and format each partition (THIS WILL DELETE YOUR DATA). You'll need:
      • 1st Partition 512 MB formatted in FAT32
      • 2nd Partition the rest of the SD formatted in EXT2
    2.  Install the APPs listed above
    3. Open Link2SD
    4. You should be greeted by this screen

      1. Select ext4 and press ok
      2. When prompted reboot your device
    5. Open BusyBox
      1. Press INSALL 

    Installation

    Update 2/2/17

      'sana' suit has now been removed from Kali's repositories and kali-rolling is installing correctly.
      1. Open Linux Deploy (From here on ensure constant Wifi connection and power)
        1. Press your phone's menu buton
        2. Press status
        3. Under Available mount point there should be something like /data/sdext2, make note of that.
        4. Press the button on the right (looks like a download icon)
        5. In Distribution select Kali Linux
        6. In Distribution Suite select kali-rolling
        7. In Architecture select armhf
        8. In Installation type select Directory
        9. In Installation Path type in the path you took note of before
        10. (Optional)  Change Username & Password
        11. Set DNS server to 8.8.8.8 (Google's Public DNS server) since the default tends to fail
        12. Finally, set Localization to en_US.UTF-8

        13. Make sure in Select Components that Kali Components IS NOT SELECTED
        14. Press Install
        15. This might take a while ...
        16. When you see "<<<install" on Linux Deploy's logs the installation has finished
        17. (If there was no error your system is now ready to boot).
        18. Press Start 
        19. Press Ok
        20. You should see something like this

        21. If you see a lot of skips then something went wrong during the installation
      2. Now from ConnectBot (or a machine in your local network) ssh to yourusername@theipontopofLinuxDeploy (in this case xxxx@192.168.1.2)
        1. sudo dpkg-reconfigure locales
        2. sudo locale-gen
        3. sudo nano /etc/apt/sources.list
        4. Delete all its contents and replace them with the following
        5. deb http://http.kali.org/kali/ kali-rolling main contrib non-free
          deb-src http://http.kali.org/kali/ kali-rolling main contrib non-free
          deb http://security.kali.org/kali-security kali-current/updates main contrib non-free
          deb-src http://security.kali.org/kali-security kali-current/updates main contrib non-free
        6. Send Ctrl+O (to save the file)
        7. Send Ctrl+X (to exit nano)
        8. sudo apt-get update
        9. sudo apt-get dist-upgrade
        10. (if prompted)
          sudo apt-get autoremove
        11. sudo apt-get install kali-linux-full
        12. PATIENCE, since this will download around 4GB of data
      3.  If everything went right you should now have a working setup of Kali Linux on your Android phone
      Hope this helps a few people skip a bit of the frustration. Have fun!

      Clarification: There is a reason behind selecting sana suite (initially) and then changing the deb sources to kali-rolling (and kali-current for security). When selecting Kali-Rolling as a suite the installation (step 15) was observed to repeatedly fail. On the other hand, sana suit being discontinued is lacking a few dependence (or has wrong versions) and will fail during upgrade sending you on a long trip of compiling dependencies from source and iterating.  

        Monday, January 18, 2016

        Maintaining a sorted array of tuples ~ Python

        Hello Pythonistas!

        After some Christmas despair and endless reference searching  I thought I could do a good thing and put everything together here ;)

        Objective : Maintain a sorted array of tuples in Python

        For our recipe you will need : 1 array of tuples, 1 array of comparable values , this post

                The main array (from now on "tupArray") is an array of tuples (say tuples of three values) so we have tupArray = [(0,0,0)]  keep in mind the value we want to use to keep the array sorted HAS to be comparable. The second array (from now on "indexArray") is going to act as an index for the first so it will be sorted too and it will contain the element from each tuple that is our sorting index. Confused? Let me clear it out a bit with an example. Say we want to sort our array of tuples based on the second value of each tuple. This would be tupArray[i][1].  Then given an already populated and sorted tupArray, the indexArray would be created like this:

        for elem in tupArray:
             indexArray.append (elem[1])
        

                That's it. We now have both tupArray and indexArray populated and sorted. Now to maintaining. This was probably the hardest part, not to understand but to find information about. First make sure you're familiar with slicing, you can tag along in any case but having a basic understanding of slicing would help you understand much faster.
                We will be utilizing a function called bisect. What bisect does is it returns the position in which you would insert an element in a sorted array in order for it to remain sorted. Bisect has a few variants, that allow you to define whether you want the new element to be placed before or after any existing elements with the same value (bisect_left is for before and bisect_right is for after we will be using the later). First import bisect:

        import bisect

        Then we call bisect giving indexArray and the element to be inserted as values:

        insertIndex =  bisect.bisect_right (indexArray, elementToInsert)

        Then we place it in indexArray using slicing:

        indexArray[insertIndex:insertIndex] = elementToInsert

        This will create a NEW element at indexArray[insertIndex] and not replace the one already there (like indexArray[insertIndex] = elementToInsert would). Finally, we have to insert our tuple to tupArray. For that we'll be using slicing again:
        tupArray[insertIndex:insertIndex] = tupleToInsert

        And that's really all there is to it! We've made an index list out of our array of tuples and managed to insert a new element without having to resort the array. A little heads up, if you are to pop or in any way remove elements from tupArray (and you most probably are) REMEMBER to do the exact same operation to indexArray too!

        Until next time, have fun and happy coding!


        Sunday, November 29, 2015

        What was and what is JustAddCoffee

        A question I've come to ask my self a lot of times as the brand progressed. Initially, in April 2014, we created JustAddCoffee with the vision of making a gaming blog, not to get filthy rich, but as a way to express our views and share the joy we got from the games we played, and the occasional frustration.

        Along the way, seeing that not many people would choose to read in their free time (not from the gaming community we were addressing at least), we decided to give YouTubeing a shot. Although we put considerable amount of time in it, it was never enough. YouTube, especially when it comes to gaming channels, has a pretty strongly established base. The main challenges was the time it required to produce a decent gaming video and the equipment it required to produce a hardware review. So having limited available time and a vary small budget we eventually let go of YouTubing.

        So this WAS JustAddCoffee, the above followed a period of inactivity, at least in our public pages. During this period, we were redefining what JustAddCoffee was and so we get to what JustAddCoffee is now.

         The fact that we were both programmers and long time gamers gave us a head-start in game development. So yes, that's what we're into right now, Indie game development. We've tried many development platforms, from dead simple to exhaustively  complicated, and experimented with many genres. Finally we've settled to our choice and are now developing our first game hopping to give something new to the gaming community.

        So that's who we were, that's who we are and if you want more ... JustAddCoffee!

        Monday, July 13, 2015

        Elephone P3000s First Impressions


        So this isn't going to run as a review but more as first impressions post (as the title suggests). So I've had the Elephone P3000s for about a week know and thought about sharing the feel that I get from using it.
        Right off the bat I'll say that initially I chose the brand and the model for the ration of specs/price. At the moment I purchased it, it was around 150 euros and it came with a tempered blueglass and the official case (an it does matter).
        Things I loved about it and things that let me down. Well as I said before the first thing is the specs/price ration there's just no way you can't love it. Second comes the design of the phone, elegant simple and a bit blocky (not totally roundish). The colors are also pretty amazing. Then, watering down a bit, we move to the battery life. The battery life is good, just that nothing special. But being a guy that charges all his electronics every night, well it doesn't really affect me. To close with, and the only outright let down, is the fingerprint scanner. It's just not usable. It works, but it's so damn hard to get it to recognise your fingerprint, as it's angle sensitive, that nearly every time I exceeded the maximum tries and had to use the alternative password, eventually rendering useless the whole system. If you're absolutely looking for a fingerprint unlockable phone I'd recommend getting a later model with a touch ID system (where the fp-scaner is located in the homescreen button and is a bit more agile).

        All in all, it's a great device with a great specs/price ration and will cover almost any user's need. I've been using it for video streaming, for games, and for e-mail and document viewing and can't complain about anything. Also used it as a hotspot for a while, but not enough yet to have a complete view.

        That's all for now!

        (This was to be uploaded to www.justaddcoffee.org but due to some changes we're implementing to the server the blog will be down for a while)