Tuesday, January 9, 2018

Phone Monitor

I had made a basic phone monitoring program using B4A some years back just out of curiosity. I had a fairly good grasp of malware programming in Windows, so I had thought of giving my mobile phone's OS a try with it. Basic felt easy since it was the language I was most accustomed to using then, and it was Basic, for Android. The mobile OS itself was still not very mature so a lot more loopholes than now and certain things were more easily doable, not to mention the availability of third-party libraries for B4A. Anyway, I never released it; must be sitting around somewhere on my old desktop's hard disk.
The above program is not what this post is about though. This blog has seen me transform from a quick and dirty vb6 - read procedural - programmer to a relatively organized, more modular C# - say OOP - coder. I write OO programs now. I taught myself Java too, not too different from C#. So, about two weeks ago, I made up my mind about giving a new Android project a go, this time not in B4A, but in Java, the mainstream language that most Android apps are written in (that may change to Kotlin in the future, who knows), and in determining what, I figured why not make a better, updated, extended version of something cool I'd created before. The result is PhoneMonitor.
The old program was called SMSLogger because I'd built it up from exactly that, a program that would upload the target Android device's SMS messages to a specified FTP server. In its final form, it was capable of doing more than that of course, like recording phone conversations, listening for SMS based commands to do some fun stuff like vibrating the phone or more useful stuff like retrieving the phone's GPS coordinates, calling a specified number, messaging a specified number etc. So, this PhoneMonitor follows a similar development path but is more comprehensive and geared towards web panel based command and control rather than SMS'es (one of the reasons being the new security features concerning SMS write/broadcast permissions in Android KitKat and above. Life used to be easier back in the Gingerbread days.) The major functionalities include retrieving call logs, contacts, sms messages, device location (this too is harder than used to be), back and front camera pics, command to call, send an SMS, vibrate, enable Wifi - oh, and of course, it records phone conversations and uploads them to the specified FTP server.
The full source code for the app and the web panel along with some screenshots is available @ github

Tuesday, November 21, 2017

Unicode-Preeti-English Transliteration

Days ago I wrote python scripts for converting texts between Unicode, Preeti and English(transliteration). The initial motivation was to convert Unicode Nepali names in a database to their English transliterations for the ease of carrying out SQL queries. That led me to put together the first script. One or two days later, a friend of mine asked if I could write something for converting between Preeti and Unicode and so I gave it a try and consequently produced Preeti to Unicode and Unicode to Preeti scripts.
The above scripts at their core are mapping-dictionaries complemented with rules for outliers/exceptions that occur rather frequently during the conversion process. As a result, they probably aren't perfect but can certainly be refined to near that.
Now, the only thing missing is conversion from English to Unicode which I don't think is necessary because ... Google Input Tools - among other alternatives.
Oh, and while I was pushing revision commits to the Unicode to Preeti script on GitHub, I wondered if there already was a better, reliable program for it. So, I searched GitHub for any existing 'Unicode to Preeti converter', and among others, I landed upon this which is pretty good at its job.

Saturday, May 6, 2017

CSArp Netcut

I use Arcai's Netcut sometimes. It works. But sometimes, it abruptly crashes and doesn't go quite as easy as I would like it to. I found it to be a little too sluggish.
Then I thought to give SharpPcap a try, just to fool around, to see if I could capture some packets here and there, knowing that it must be such an insurmountable task to complete such a project, especially with the limited networking knowledge I have. But, one thing led to another and I had dived in too deep. On the first day, May 4, 2017, I tried using the GetIpNetTable API to get the ids of devices currently connected to my LAN. It was a tough thing for me to finally get something of some value that could accomplish some semblance of my goal. The entire day, I spent searching the internet for that one API and gluing together pieces to make it tick. And tick it did but I realised the system ARP table information it provided was little indication of all the devices of my LAN. Frustrated, I slept on it.
The next morning, I actually started fiddling with SharpPcap, it was a low level based high level API after all. I quite successfully and pretty quickly realised that capturing ARP packets with this .NET library was trivial and upon analysing numerous Debug.Print() outputs from my Visual Studio 2017's Output Window of the captured packets, and knitting them together with the information I gathered on ARP from the internet, I finally pieced together a method to produce a list of devices connected in the LAN. In short, I did it by basically sending ARP Request packets to every possible IP on a LAN that utilises the ipv4 protocol. Then, to actually perform an ARP spoofing/"cache poisoning" attack, I tried some 4-5 combinations of Requests/Response/To gateway/To target device/Broadcast/"Unicast"(targetted transmission) packets. That day, I was unable to make it work without raising alarms on the target device; for instance, when sending(Unicasting/Broadcasting) ARP packets(Request and/or Response) pretending to be sent by  the gateway device(router in my case), my desktop's ESET Smart Security 10 shouted at the screen non-stop and while it did work on my android phone, I wanted my program to work on every device, like Arcai's Netcut seemed to, so cleanly. It was yesterday.
Determined to get it right, today morning, I changed the code to send targetted ARP requests to the gateway, while pretending to be the target device. I ran it and voila! It worked perfectly. No alarm bells or warning signs. It just worked! With some cosmetic touches to the program(which took, as they always do, significant amount of time for the auxiliary function they serve) I uploaded the first version, 0, to GitHub. After that, I immediately thought of why I wanted so desperately a program like Arcai's Netcut in the first place and added some improvements/extra functionalities. And just some time ago, I published it in my GitHub repository for the program.
So.
Here it is, in its infant glory...


It may be brittle yet. But it works for me, and it's open source. So, feel free to do anything and everything with it.
Download here
GitHub @ here
PS: SharpPcap, used by this application, requires WinPCap to be installed. At the time of this writing, it can be downloaded from here

Thursday, April 27, 2017

CSWall

A C# equivalent of pyWall I wrote yesterday.
Simply fetches random images matching the specified categories from 500px.com and sets them as desktop wallpaper in specified intervals of time.


Download here
Project @ github

Saturday, March 4, 2017

pyWall

A simple script for periodically changing windows desktop wallpaper written in Python 3.5
It took me 2 days to bring it to "completion".
The UI was very difficult to write, especially with multithreading.
The primary reason I chose python instead of say, C#, was the easy availability and ease of use of libraries such as Requests, BeautifulSoup and the like; and while the core functional part of the program was completed relatively quickly, actually polishing the program further, I found, was very tough in python.
Needless to say, there's a lot of stuff that could be improved on but I don't think I will be continuing this project with python any more. I found it very cumbersome to say the least.

Anyway, here is the UI of the program:
The actual script is available here
Installing Anaconda with Python >= 3.5 is recommended since that's what it was written under.

Saturday, December 31, 2016

Simple Single Layer Perceptron in VBA

I've been tinkering with machine learning and AI for some days now. I've come across TensorFlow, what seems to be the standard library to use for machine learning these days. But to use it and to understand what it was actually doing underneath the high level APIs it provides, I searched for the most basic of machine learning codes on the internet.
I found a great C source for a single layer perceptron(a simple linear classifier based on artificial neural network) here by Richard Knop. I studied it and thought it was simple enough to be implemented in Visual Basic 6. And because it would be useful to represent training and test data in a graphical form, I thought Excel VBA would be better.


So, here it is.
What's being done in the excel file is this: 20 $(x,y)$ data that fall in the $(-,+)$ quadrant of the XY plane are generated in random with the constraint $x \in [-5,0]$ and  $y \in [0,10]$ and 20 that lie in the $(+,-)$ quadrant with the constraint $x \in [0,5]$ and $y \in [-10,0]$. These fill the first two columns X and Y of the worksheet. The next column is the $y$ data from the line $y=x$ for checking the prediction validity later whether a given $(x,y)$ falls above or below this line, which we know beforehand and with certainty that divides the two classes of data linearly. So, the fourth column Bool represents what the prediction should be i.e. it is a column of the boolean expression : column 2 $>$ column 3, for use as a benchmark and more importantly for use as the training data for the algorithm. The next column Prediction is the actual output of the perceptron after being fed all the 40 training datasets of $(col.1,col.2,col.4)$. The remaining two columns are only auxiliary and show a measure of the overall accuracy of the predictions it made on the same training datasets used as test.
And, since the activation function used in this single layer perceptron is just a unit step/threshold function $$t(p(x,y)) \text{ where,}\\  p(x,y)=w_1x+w_2y+w_3$$ that returns 1 for any non-negative input i.e. $>=0$, the function $p(x,y)$ is essentially the equation of the line that, the algorithm guesses, best separates the two classes of data.

Wednesday, February 10, 2016

Plane Truss solver

This is a simple program to solve determinate plane trusses with point loading at pins.
There is a lot of room for improvement: the interface is basic, more features could be added, but it works.
Download here