Friday, 9 March 2018

Everwing hacks

Play everwing,

F12 to open up dev tools.
Maybe esc to bring up the js console or maybe it is already open.


GC.app.gameModel.extraLives = 100000;
GC.app.gameModel.itemSpawnMultiplier = 10000;
GC.app.gameModel.timeMult = 0.5;
GC.app.gameModel.energyEarned = 10000000;

There are many more.
explore objects/keys on GC.app.gameModel

Find globals left in a website/webpage/webapp browser based game etc.

Visit a clean blank webpage in chrome.
Press F12 or goto JavaScript console.

Copy and paste this in.
It will get a list of all the keys exposed on window object. (Globals)


var _KEYS_ = {}
for (var key in window) {
_KEYS_[key] = 1
}
copy('var _KEYS_ = '+JSON.stringify(_KEYS_) + "; Object.keys(window).filter(function(key){ return !_KEYS_[key] })")

Next visit the page/site you want to look for exposed globals on.

Somtimes devs forget to write a var keyword or they leave globals in for debug reasons.

Paste the clipboard contents into the JS Console.
It will output an array of exposed global variables.

Thursday, 2 March 2017

Sublime text cutting when I want to delete? (Shift+Delete is Cut)

Selecting some stuff to cut, then selecting rest of code to delete causes what I want to delete to be copied to the clipboard.

Because  Shift+Delete is Cut hotkey for some archaic reason.

A pain in the ass, because obviously I want to delete what I selected and not cut it to the clipboard.
Okay, I could just slow down and wait to left my left pinky depress left shift fully.
But blah, fuck that.

I found I can over-write the default keymap for shift+delete (and some others) made it delete_word which is way more helpful.

Preferences | Key Bindings

Paste this into the User keymap.


[ { "keys": ["shift+delete"], "command": "delete_word" }, { "keys": ["ctrl+insert"], "command": "none" }, { "keys": ["shift+insert"], "command": "none" }, ]

Thursday, 8 December 2016

UnhandledExceptionFilter wont compile in VS2015 but worked in VS2012 Already defined. Also VEH to detect unpacked ASProtect.




If you are using UnhandledExceptionFilter in a C++ application and try to compile with VS2017 (It worked in 2012 just fine)

And you get the error message

Severity Code Description Project File Line Suppression State
Error LNK2005 _UnhandledExceptionFilter@4 already defined in kernel32.lib(KERNEL32.dll) ...
Error LNK1169 one or more multiply defined symbols found ...


And you also have a function called UnhandledExceptionFilter

Try renaming it to something else.

The compiler or linker? im not sure which.
Rename the method to _UnhandledExceptionFilter which conflicts with one in kernel32 when linking....


What the heck.


A bonus content for you.

I detect if the ASProtect packed target executable is unpacked by using a VEH
I use an injected dll to run this code and the rest of my code inside the target process.
I start the process suspended, inject dll then resume the main thread.



VEH Handler

DWORD test = 0;
DWORD exceptionCount = 0;
LONG WINAPI MyUnhandledExceptionFilter(EXCEPTION_POINTERS *pExceptionInfo)
{
void* Eip = (void*)pExceptionInfo->ContextRecord->Eip;

exceptionCount++;

// sprintf(Message, "Exception Count: %i\nException Code: %X\nEIP: %p\nRegisters\n\nEAX: %X EBX: %X ECX: %X EDX: %X\nESP: %X EBP: %X\nESI: %X EDI: %X\n",
// exceptionCount,
// pExceptionInfo->ExceptionRecord->ExceptionCode,
// pExceptionInfo->ContextRecord->Eip,
// pExceptionInfo->ContextRecord->Eax, pExceptionInfo->ContextRecord->Ebx, pExceptionInfo->ContextRecord->Ecx, pExceptionInfo->ContextRecord->Edx,
// pExceptionInfo->ContextRecord->Esp, pExceptionInfo->ContextRecord->Ebp,
// pExceptionInfo->ContextRecord->Esi, pExceptionInfo->ContextRecord->Edi);
//MessageBox(null, Message, "Debug", MB_OK);

// We know the game is unpacked when the exception has a PUSH 0C after it.
// This just seems to be the way it is for asprotect. See Tuts4You Loaders.asprotect1.pdf
BYTE* oData = (BYTE*)Eip;
if (oData[19] == 0x6A && oData[20] == 0x0C)
{
// Game is unpacked in memory and memory security check is done.
// This just detours the games init function. (I couldn't detour it reliably without this code because some faster computers would have already run it, and slower computers might not have even unpacked by the time my dll inits. Sleeps were not a good solution.
origInitGame = (t_InitGameFn)DetourCreate((LPVOID)0x00403180,(LPVOID)initGameHook, DETOUR_TYPE_JMP);

isGameUnpacked = true;
return EXCEPTION_CONTINUE_SEARCH;
}

return EXCEPTION_CONTINUE_SEARCH;
}


Add the VEH

hVEH = AddVectoredExceptionHandler(1, &MyUnhandledExceptionFilter);
if (hVEH == NULL)
{
MessageBox(mainhWnd, "Error VEH 1.", "DLL ERROR", MB_OK + MB_APPLMODAL);
return 0;
}


// Check while its not unpacked. This serves as a timeout.

int pCheckUnpackedCounter = 0;
while (isGameUnpacked == FALSE)
{


if (pCheckUnpackedCounter > 60000)
{
// Roughly 1 minute.
// Unable to detect unpacked game code.
// Remove our vectored exception handler, it has done its job.
RemoveVectoredExceptionHandler(hVEH);
MessageBox(mainhWnd, "Error VEH 2.", "DEBUG", MB_OK + MB_APPLMODAL);
ExitProcess(1);
return 0;
}

Sleep(1);
pCheckUnpackedCounter++;
}


Remove the VEH when its done its job.


// Remove our vectored exception handler, it has done its job.
RemoveVectoredExceptionHandler(hVEH);

Tuesday, 8 November 2016

jQuery make input element select value when it gets focus.

I think this makes inputs more user friendly in that focus can be assigned and the user can start typing to replace the number.

// A behavioural change to all input elements.
// Make them select the text when they get focus.
$(document).ready(function() {
    $('body').on('focusin', 'input', function() {
        console.log('Input selected:', this.id, this.name);
        $(this).select();
    });
});

Friday, 26 August 2016

Private VPN for playing games or using other software as if two or more LAN's were connected.

Got sick of hamachi screwing out.
https://nwgat.ninja/quick-easy-tinc-vpn-between-windows-systems/

And if you want to play games that use IPX but dont want to install IPX use one of these to wrap it with UDP.
http://www.moddb.com/games/cc-red-alert-2/downloads/ra2yr-lan-fix-xp-vista-w7-x86-x64
or
http://www.solemnwarning.net/ipxwrapper/

Wednesday, 23 September 2015

MSSQL Context_Info session value global value.

How to store and read bits from a session value called Context_Info.



SET Context_Info 0xFF; -- bitindex is the value of the bit you want to get for example 7 is a value of 64 or 0x40 -- CONVERT(tinyint,bitindex value) & SUBSTRING(Context_Info(),byteoffset+1, 1) select CONVERT(tinyint,0x01) & SUBSTRING(Context_Info(),1,1) AS '1', CONVERT(tinyint,0x02) & SUBSTRING(Context_Info(),1,1) AS '2', CONVERT(tinyint,0x04) & SUBSTRING(Context_Info(),1,1) AS '4', CONVERT(tinyint,0x08) & SUBSTRING(Context_Info(),1,1) AS '8', CONVERT(tinyint,0x10) & SUBSTRING(Context_Info(),1,1) AS '16', CONVERT(tinyint,0x20) & SUBSTRING(Context_Info(),1,1) AS '32', CONVERT(tinyint,0x40) & SUBSTRING(Context_Info(),1,1) AS '64', CONVERT(tinyint,0x80) & SUBSTRING(Context_Info(),1,1) AS '128'


You can also store strings in it.

DECLARE @MyStatus VARBINARY(128); SET @MyStatus = CAST('TEST' AS VARBINARY(128)); SET Context_Info @MyStatus; SELECT CAST(Context_Info() AS VARCHAR) -- Or substring :D SELECT CAST(SUBSTRING(CONTEXT_INFO(), 1, 4) AS VARCHAR)



This Context_Info value could be useful to store a value for the session and change the control flow of a trigger.

Monday, 19 January 2015

Moving from Tomboy to GNote for note keeping on ubuntu.

So I had a bunch of notes stored in Tomboy on an older version of ubuntu.

When I upgraded to a newer version of linux I found out I just could not use tomboy notes.
I read somewhere that tomboy was officially removed as a default note app/in apt-get repository the author of that message recommended GNote.

When I installed it, it conflicted with google chrome and uninstalled that automatically.
Re installing chrome would remove Tomboy.

The solution is to use GNote which I think is actually nicer and to copy the *.note files from tomboy to your gnote directory in ~/.local/share/.

sudo apt-get update && sudo apt-get install gnote
cp ~/.local/share/tomboy/*.note ~/.local/share/gnote/


You may also want to auto start gnote

mkdir ~/.config/autostart
cp /usr/share/applications/gnote.desktop ~/.config/autostart/
chmod u+x ~/.config/autostart/gnote.desktop


Thanks to http://www.irrational.net/2012/04/27/moving-from-tomboy-to-gnote/

Wednesday, 14 May 2014

Oracle Database not replicating or SSL not working.

Check the date time on the server/computer.....
Make sure its set correctly, Enable Network Time Protocol syncing....

Check the cmos battery.
Yip we had a powercut and a machine we are using as a db server had the cmos battery go flat so the date was in the past. Records created after that date were not synchronized to other servers and the logs were of little use.

Thursday, 27 March 2014

Preventing spelling mistakes with Sublime spell checking

So people seem to get annoyed at spelling mistakes in my comments and code.
I'm not very good at English. Turns out sublime has a solution.

I just have to enable these settings under Preferences Settings - Default or Settings - User etc.
"spell_check": true,
"dictionary": "Packages/Language - English/en_GB.dic"

If you use US spelling you could set your dictionary too
"dictionary": "Packages/Language - English/en_US.dic"

Yeah.. I use GB at work because I live in New Zealand and we spell things with UK spellings.
Eg Colour not Color. I much prefer US spelling but not much that I can do about that since everyone else would expect things to be spelt how they want right?

https://www.sublimetext.com/docs/2/spell_checking.html

It adds commands to the right click menu when right clicking on words where you can ignore or see list of corrections. And words are underlined with a red triangle wave squiggle.

It checks comments and strings in ' ' " " etc.

Very Useful.

Saturday, 22 March 2014

Signature Scanning

I have been getting a lot of questions about Signature Scanning such as

  • What is a signature?
  • How do I find or make one?
  • Where would signature scanning be usefull?


People seem to think this is a hard thing to do so I want to try simplify it.
Basicaly code such as C++ is compiled it is turned into byte code that the computer can run.

When memory hacking we find bytes we want to modify but if the application is recompiled or uses dynamic memory
The address is not garruented to be the same each time the app runs.

A signature is a sequence of bytes and wild cards to find in memory.

I have a game here, and it has a version string rendered in the bottom left.
You may be able to see VER9.02

I wanted to get that version as well as modify it to include my own text.

So I used cheat engine and searched for a string of VER9.02
I had to have Writable and Executable checkboxs set half way so that Cheat engine would scan
readable and executable memory too.

After I found the version string address.
I found what accessed the code.

Which can be done two ways, scan for the address in hex and goto the address -1 in the Memory View dissasembler
Or right click the entry and find what accesses.

I can just scroll up a little bit and look at the bytes on the left. Any references to other memory addresses
will change on recompile, such as ones seen in the PUSH or MOV or CALL op codes
Generally if the value is in the code sections of the executable it will be suspect to change.
Simply make those bytes wild card with the ?? when writing them down. You can search the signature in cheat engine
As an array of bytes with hex turned on.


Signature Scanner: https://code.google.com/p/signiturescanner/


Video can be found here: https://www.youtube.com/watch?v=WmHDQzfELxk


Thursday, 26 December 2013

Reversing data to figure out the math behind generating values using Eureqa Pro

So I needed an easy way to get the formulars back from the data in a game.
For example to know how Damage and Chance to Hit are calculated so that I can emulate this server side.

I needed something simple to use, there was R which I learnt about at work but its unnessecarly complex.

Erueqa Pro has a spreadsheet interface to enter your data, you define var for each column.
dex hitrate
1 5
2 10
3 15
4 20
5 25
6 30
7 35
8 41
9 46
10 51
11 56
12 61
13 66
14 71
15 77
16 82
17 87
18 92
19 97
20 102

I then went to the Set Target area. I knew Floor, Ceil or Round must be used as the value is always a whole number but the total goes up in a pattern like 3 2 2 2 3 2 2 3 2 2 2 which tells me theres flooring or something going on.
http://www.nutonian.com/download/eureqa-desktop-download/

Tuesday, 22 October 2013

Using Python in IDA Pro to iterate over functions and name them


The following code finds what calls the function GameSendPacket,
It then iterates through each function till it finds the opcode of mov with param of byte ptr[xxx]
It then reads the hex param which happens to be the packetID for what I am using this for.

Then it goes to the function and gets its name, if it starts with sub_ then its just been named automatically by IDA so then rename it to be SendXX where XX is the packetID woo!



for ref in CodeRefsTo(LocByName('GameSendPacket'), 1):
   E = list(FuncItems(ref))
   if len(E) == 0:
     print "ORPHAN CALL (NOT IN A FUNCTION)!!!!"
     print " at %X " % ref
     continue
   for e in E:
      if (GetMnem(e)=="mov"):
         p1 = GetOpnd(e,0)
         if (p1=="byte ptr [eax]" or p1=="byte ptr [ebx]" or p1=="byte ptr [ecx]" or p1=="byte ptr [edx]"):
            OpHex(e, 1)
            n = GetOpnd(e,1)[:2].zfill(2)
            OldName = GetFunctionName(ref)
            NewName = 'Send'+n;
            FuncAddr = PrevFunction(ref)
            print '%s NewName: %s OldName: %s' % (hex(FuncAddr), NewName, OldName)
            Jump(FuncAddr)
            if (OldName.startswith('sub_')):
               print 'Rename %s to %s' % (OldName, NewName)
               MakeName(FuncAddr,NewName)
            break


Funtimes.

Now to make one for handling recv array.
And maybe later graphing GUI click events through to their packets they send.

Calling Functions and getting a String from the pointer of their input and also Javascript in IDA Pro

So I learnt about a thing in IDA pro called Appcall which allows you to call a function you have defined *Which can be done with N*

You have to pause in debugger before using this.

I found a function called it GetMessageFromID it was a this call with 1 argument So I needed to know the pointer. I breakpointed it and got it called once then put the argument in and it worked as expected. I got back an address.

I thought this is good but I want to see the string.

In IDC you can use
GetMessageFromID(0x00A59000,1)

In Python
Appcall.GetMessageFromID(0x00A59000,1)

A loop in python printing out the String value :)
for x in xrange(0,1000):print GetString(Appcall.GetMessageFromID(0x00A59000,x))

Just printing out a string
print GetString(Appcall.GetMessageFromID(0x00A59000,10))

Also we can use javascript as a scripting language which is much nicer than python and quite similar to IDC.
http://www.hexblog.com/?p=101

I am installing it now hopefully it works great for me coding unpackers or bypassers or helper functions in js seems quite good.

Friday, 11 October 2013

node.js Load and execute code at runtime

This is usefull when you have scripts you want to reload and execute at runtime.

function LoadJS(file, callback) {
console.log('Trying to load: ' + file);
fs.readFile(file, function(err, data) {
if (err) {
console.log(err);
if (callback) callback(err, file);
} else {
try {
eval(data.toString());
} catch (exception) {
console.log('Error loading ' + file, exception);
if (callback) callback(exception, file);
}
}
if (callback) callback(null, file);
});
}


Remember the contents of eval will be executed in global scope.
If you were using it through an object like
this.LoadJS = function(file, callback) { ...

Then before you could do something like this
var Something = this;

and in the js file you load
Something.W/e you want.

Thursday, 3 October 2013

Using Virtual Box to emualte a Physical / Real hard drive.

I recently setup a new computer to use at work, moved the hard drive from my old one with Windows8 onto it. And decided to try to boot it from VirtualBox rather than having to dual boot when I needed to work on windows software. *using it for windows phone 8 development*

Turns out its possible,

An awesome guide here.
http://www.theunixtips.com/virtualbox-use-raw-disk-to-load-windows-under-linux

Windows 8 will notice your hardwares different and you will need to repair the bootloader and os with the cd.

Just use these commands which I found out about here: http://www.tweakhound.com/2012/11/13/how-to-fix-the-windows-bootloader/

bootrec /fixmbr (writes mbr but does not overwrite partition table)
bootrec /fixboot (writes new boot sector to system partition)

Then you will be able to use Windows8 from your operating system. In my case Linux Mint 15 Cinnamon.

Friday, 3 May 2013

View Chrome Web History without access to computers account

Something that was very helpfull to me recently was being able to access Chrome's web history and search terms of a computer that I didnt have the login for.

I was able to successfully work out the information I needed.

The files are located in the application data under Google then Chrome then User Data

Windows 7/vista:
C:\Users\<Username>\AppData\Local\Google\Chrome\User Data\Default


They are SQLite DB files.
See the History or any of the History Index files.

You can query them with any SQLite tool
http://sourceforge.net/projects/sqlitebrowser/


The time format used in chrome is a bit weird heres how to get it into a usefull datetime.

SELECT id,title,url,datetime((last_visit_time/1000000)-11644473600, 'unixepoch', 'localtime') AS time FROM urls


Optionally tack on something to search for all titles that are like bus
 WHERE title LIKE '%bus%'


I was able to export csv and xls using this tool.
http://www.speqmath.com/tutorials/sqlite_export/

Tuesday, 16 April 2013

Extracting ZLIB compressed data from any file

This is very usefull for analysing file formats that contain compressed data.

You can use a handy tool by Luigi Auriemma found here http://aluigi.altervista.org/mytoolz.htm#offzip

Extract it and put it in a directory somewhere, for example

Make sure you choose a drive with lots of space.
C:\offzip\

In the directory, make a bat file called extract.bat
With these contents


mkdir %1.out\
offzip -a %1 %1.out\ 0

this will make a directory for your extracted data to go into so things don't get messy it will be the file name with .out at the end of it.
Then it will instruct offzip to find all compressed data it can in your file and extract the parts out into the directory made. It will start from offset 0

You can see the address the compressed data was found at in its filename.

Quite handy.

I also came across a great blog here, http://www.se7ensins.com/forums/threads/tut-how-to-mod-darksiders-using-offzip-and-packzip.153898/
Which shows how you can, extract->Edit->pack back in to edit game save files.

Writing Node.js modules

So from making a server side emulator for a mmorpg in node.js I have learnt some ways to make modules.

Here I will be sharing some of the ways to write them

<script type="syntaxhighlighter" class="brush: js"><![CDATA[


(function() {
// Put any requires your module needs here

var YourObject = function(func) { // Has example of passing in a callback,
// Any private values you could put here
var something = 1;

// Here is where you can put public propertys and what not
   this.Something = 1; // public propertys here

   if (func) this.func = func; // Overrides the prototype func
}

// You can also put public/protected functions here using prototype
YourObject.prototype = {
        func: function() { console.log('Not yet implemented'); } // Used if func not passed in as paramater :)
getID: function() { return this.ID; },
getName: function() { return this.Name; },
};

module.exports = YourObject;
})();

//To make it work on web client and node.js server
var obj = new YourObject();
//Or you could use reference to your object rather than an instance of it depending if you want to create more of it or only have 1

if(typeof module !== "undefined" && module.exports) {
    module.exports = obj;
}
if(typeof window !== "undefined") {
    window.YourObject = obj;
}
]]></script>

Simple eh. In node to have private functions I guess you could put them in the scope outside your object.
But in web browsers this may pollute the global scope.

http://ejohn.org/blog/simple-javascript-inheritance/