Termux on Android phone

As previously mentioned and clearly visible due to the relatively low / lack of content posted over the past 18-months, I have been somewhat distracted by the work / owrk thing.  Yes, it does pay the bills & keep a roof over my head; but I could just as easily gamble on the stock-exchange, or crypto-currency, or do presentations at Glastonbury about UFO UAPs in order to pay the bills.  I however choose to stay in corporation land and get under-paid and under-appreciated for what I do - knowing my mere existence annoys upper-management makes it all worthwhile.  Besides, I work in delivery services, basically I am pimped out from my company to do whatever a customer / client wants me to do: mostly that is to save them or earn them more money; I don't get a proportion of that, I get below basic wage (yes, that is a fact and is even published online someplace)... this raises the question: "why don't you quit / move job?"

Well.....I actually like working for the customers / clients that I work for, they are nice, they appreciate what I do - now, whether that is like a human/cat: cat/human relationship, I'm not sure, but you get my drift.

WTF has that got to do with Termux?  Nothing...and everything...

Oh yay! Tony has found a terminal session can be run on his Android phone, whoopee!  Actually, I've been able to run terminal sessions (SSH) on my Android phones since, at least, 2015-ish, so you are right, nothing NEW here.... or is there?
Well, yes, yes there is....For starters, you don't need to /root your phone (what what what?!):
BLURB:

Termux is an Android terminal emulator and Linux environment app that works directly with no rooting or setup required. A minimal base system is installed automatically - additional packages are available using the APT package manager.

This raises many questions.

Now, maybe back in the day, aforesaid mentioned, 2015-ish, I had some nice customers / clients who were a well known UK Bank.  I was working for them doing BPM-stuff and basically I was bored.  I had a couple of Raspberry Pis, a few Android tablets and some Y-cables and some external USB WiFi connectors.  I started to play with running Linux Tools (what evolved into becoming Kali).  I started to learn a lot about penetration testing tools and cyber-security.

It was also very helpful within some of the dubious hotels that I used to stay in (yes, I spent 17-20years of my working life working away from home 3-4nights a week...pause & think about that for a minute... let that sink in....), within said hotels the WiFi signal was usually okay and I used to use some of the time in the evening / night to teach myself all about Native Cloud computing developent / deployment etc..etc.. and this usually involved uploading / downloading a lot of small files; therefore I needed a small but reasonable share of the bandwidth.  When someone from room 1401 decides that they are wanting to stream p0rn on 3-devices at once at HDMI/4K clarity, that bandwidth tended to become scarce...and you know what they say about invention and necessity.  I set about learning to use WiFi sniffing tools, how to setup M-i-M Android tablets - how to determine what URLs room 1401 was visting, if it was genuine webex/zoom calls then fair enough, if it wasn't then, fair game.... I learnt how to get their devices to drop off the network, reconnect to my device (that was connected to the hotel WiFi) and then I could throttle their usage and make it so that everyone else in the hotel had a fair share of the hotel WiFi bandwidth.  It was my Robin Hood period.  I then either lost the devices / re-formatted them, or, as I suspect, I got overloaded with more work / work - to explain that, it's not really about the work that you do during the day for the customer / client that consumes you.  You can manage that, after all that is what you learn over time; how to manage your time.  the bit that kills you is having to perform a 40-50-60hour week doing the "day job" for the customer / client, in order for the project delivery to be successful... but then still being expected to do a 20-30-40hour internal week for the company that employs you.  Now, maths was never my really strong point, but even I know a pint of beer does not fit into a coffee mug, you lose something along the way.  I lost me.  Again, what has this to do with Termux?  Everything!

Termux now gives you the freedom to do all those things I used to setup & do in hotel rooms, but right from your iPhone or Android phone - right there, in your hand!  you don't need a 2nd / 3rd laptop or a dedicated Raspberry Pi or an old re-purposed Android tablet - you can do all of this now on your phone...in your hand.  That is freakin' awesome!  Does this mean I want to go back to 3-4nights a week in hotel around the world? hell no! but I like the idea / concept of it.

Okay, so you can do nefarious things with this technology, or, you can do bring basic things that can just make life a little simpler / easier.  I'm not going to preach either way - you do you and figure out your own path in life - it's what I did, I never had any guidance or someone to follow - was it always right? nope.  did I learn a lot of lessons? yep.  You can too.

Right, Termux - what can I do with it?

Well, first things first, you need to install it, then it's a linux command-line shell, so whatever you normally do, you can do - if you want to install Python3, you can; you want to install nodeJS, you can; and the icing-on-the-cake for me, if you want to install NODE-RED (on your phone!) you can... I'll show you how... (yes, of course, I'll include a few tools that can be used for other purposes; but that's all on you, not me).  I'm going to do this on my Android phone, as I no longer have Mac stuff.

Installation - do NOT download it from the Android Play Store, apparently the version is dodgy / wrong and causes problems.  you need to go to FDroid.  Basically, that webpage gives you another link to follow - HERE.  This is where you need to be.  

https://f-droid.org/en/packages/com.termux/


You may wonder why use the FDroid installation? well, as they have split the app up into modules, those modules only trust each other if they are signed the same and FDroid have done that for you.  Once you reach guru-level, you can obtain the github repo's, build all the code yourself, sign with your own keys and do your own thing, but for now, let's just use FDroid.

BTW - you DO NOT need to download / install FDroid for this to work - you "can" use their products if you want / like, but it is NOT needed for this exercise.

Now, SCROLL-DOWN vvvvvv to this sction, that's where you need to download the latest APK file.

That link, bottom left...click it.  BTW - you need to be doing this either directly on the Android phone, or on a laptop that allows you to copy the files over to the phone.

Once downloaded, install in the normal way.

Whilst we're here, go do a SEARCH like this:


There are those extra modules I was referring to earlier.  Now, you do NOT need to install all of them, or any of them to continue, but for novelty let's install the API and Styling apps.  The API app gives you the ability to run commands from the command-line that do things with the phone, read data, interact with cameras, etc..etc.. and the STYLE app allows you to just change what the terminal colour / font looks like, you don't need it, until you do.

https://f-droid.org/en/packages/com.termux.api/

Download the APK as before - however, remember that you ALSO need to run the command within the Termux command-line as well and agree to the permissions being used.

https://f-droid.org/en/packages/com.termux.styling/


I may come back to this one at some point as it looks like it might be useful:
https://f-droid.org/en/packages/com.termux.boot/


Right, moving on, you've installed Termux, you've got an icon on your phone.  You press it.

You now see a half-screen black window with a flashing cursor and probably a raised keyboard is made visible for you to enter text.  This is okay..but you may want to connect a bluetooth keyboard at some point, just to make life easier - amusingly, I did just find in one of "save it for later" boxes a tri-folded small purpose bluetooth keyboard that I must have bought and never used, it's about the same size as the phone but then folds out in a very sci-fi way.  you can do the same, or not.

Right, you're in a terminal...and what do we do when we're first into a terminal window, like we do in every Raspberry Pi first boot... we run updates!  Interesting thing here is that we are /root user, so no need for sudo.   Am now going to attempt to repeat the commands from memory that I did at 01:00am last night, I think they wen't something like this:

$apt install update

$apt install upgrade

That gets us to the latest libraries of everything and amusingly makes us secure.  Right what do we want to do with this thing?

Well, the first thing to note is to download some important stuff:

$apt install git curl wget

$apt install python

Now, this will install Python3 and I believe pip got pulled down too.

You can test this by creating an app.py file, chmod +x app.py and then python app.py and you should see the results, ta da!  you now have Python running on your phone.

You can then do things like:

$pip install nltk

and OMG!, yes it downloaded and installed and from within your app.py code, you can now do Natural Language Toolkit processing of text - OMG! that is amusing:

[actual phone screenshot]


https://wiki.termux.com/wiki/Getting_started

However, re-typing the 200-lines of Python NLTK code that I have on my Ubuntu laptop using the onscreen keyboard or even bluetooth keyboard does not sounds appealing to me.  How do I get files / on / off / accessible to this environment?  Well, if you do the following:

$pwd

$ls -l

you should notice that we are buried within a sub-folder structure that does not map to the Android phone structure... also, how do I get access to the "Downloads" or "DCIM" storage loactions?

https://wiki.termux.com/wiki/Termux-setup-storage

Just run this command:

$termux-setup-storage

$ls -l

and now you will see a folder named "storage"

$cd storage

and now you will see "downloads", "pictures", "DCIM", etc..etc..

[actual phone screenshot]

$cd downloads

$mkdir dev

$cd dev

$nano app.py

print("hello world")

ctrl+x+y

$python app.py

hello world

Now, go to you Android file manager (CXExplorer for me)


Now, navigate to the "Downloads" folder and you will see the new "dev" folder, click on it.

You will now see the app.py file listed.  click on it.  It will open in text editor.

awesome!  now you can copy files to / from a shared location.  no longer needing to re-type hundreds of lines of code. yay!


What else can you do?  well...mostly anything you can do in a normal linux environment.  For me, the next is a no brainer:

$pkg search node

This will list the packages that contain the word node, I'm just after seeing the right name to use.  I don't recall if I did this:

$pkg install nodejs

or this:

$apt install nodejs

either way, whatever way works, it'll then install nodeJS and npm into the environment.  yay!

What other development environments can you install, ask and you get to seee:

https://wiki.termux.com/wiki/Development_Environments

But, it gets better, can we install NODE-RED in this environment? yes, yes we can:

https://nodered.org/docs/getting-started/android

You just need to do this:

$apt install coreutils

$npm i -g --unsafe-perm node-red

The install will take a few minutes...and then you can just type:

$node-red -v

[actual phone screenshot]

The familiar start-up sequence will be shown, you'll also see the latest v3 is installed.

Then open a web-browser on the phone and visit:

http://localhost:1880/

and there we have it!  A full blown node-red instance running from the phone!  

[actual phone screenshot]

HINT: if you connect your phone to the local WiFi network, use the termux-api commands to find the IP address allocated to the phone, then go to your laptop and type into a web-browser:

http://xxx.xxx.xxx.xxx:1880/

You're now node-redding from the phone itself - time to click "manage palette" and add more useful nodes and get cracking!


okay, it's not ALL a bed of roses, you need to review this page to read about the differences between Termux and Linux:

https://wiki.termux.com/wiki/Differences_from_Linux

They are mostly geek-level and shouldn't affect most people; however it is good to know this info. to save you bashing your head against a brick wall later on.

Talking of cracking, yes, of course, if there are github repo's that allow for python code to be run to do penetration testing tool education / learning, you can download them and use them.

$apt install nmap

https://github.com/htr-tech/zphisher


$pkg install tur-repo

$pkg install zphisher

and to run, just type:

$zphisher

Now, because we used the package manager to do the installation, it downloaded all the required libraries for us and did the permissions things - you can do all that manually if you want, but the above is quicker & simpler.  Then once you run the app, what you do with it is your own business.


another script-kiddy fun app is this one:

https://github.com/MrHacker-X/BruteX

$cd storage

$cd downloads

$cd dev

$apt install git

$git clone https://github.com/MrHacker-X/BruteX.git/

$cd BruteX

It is at this point that I point out that I HATE this, putting a capitalisation of the "B" for the folder name, it is such a Microsoft Windows minded thing, I'm surprised it doesn't have a huge long name with space in it too... I know, I know...it just irks me

$chmod +x *

$./setup.sh

There is a question that gets asked about using the storage location, just answer [Y] it doesn't wipe any data

Then once it's done the installation you're ready to go with:

$python brutex.py

Before fiddling with such things, you may have wanted to have done this first:

$apt install tor

and before running brutex.py, run

$tor

which will run a tor connection for you.. but hang-on, it takes the prompt in the session, you cannot type anything, so how are you going to run the brutex or zphisher apps within tor?.... lol.  if you can't figure that out, you shouldn't be running them.  also, we know you'll cheat and just Google search how to do it.

okay, to save you Googling it, just open another Termux session after running tor.  Termux will use the tor from session1 for your connectivity.


Full hat-tipping nod to this chap for making this code available for others to learn from - I agree, it's more than I've ever done, so I'll get back in my box.  However, the stuff I create / use, I cannot share publicly online...  right, back to the day job...


Oh and of course, CLANG is installed by default (I believe, if not just apt install it or pkg install it) and you can get cracking with full C/C++ coding, rather than Python  :-D

Compile And Run C Programs In Termux

and the obligatory YouTube video link too:



Enjoy.


Comments