Archive for the Programming Category

JavaScript barebones

Posted August 30, 2008 at 6:34 pm in Programming | No Comments

JavaScript has nothing to do with Java.

Comments use //.

Variable declaration with initialization syntax is

var variable_name = value/"string";

Variables follow normal programming scope. If they are created within the function, they are local only to that function and if they are created outside of a specific function, they are global variables.

Event handlers include:

  1. onabort() — Page loading aborted.
  2. onblur() — Object’s focus lost.
  3. onchange() — Object changed.
  4. onclick() — Object clicked.
  5. onerror() — Script encountered an error.
  6. onfocus() — Object has focus.
  7. onload() — Object finished loading.
  8. onmouseover() — Cursor placed over object.
  9. onmouseout() — Cursor moved off object.
  10. onselect() — Object’s content selected.
  11. onsubmit() — Form submitted.
  12. onunload() — Page has been left.

Function syntax:

function function_name() {statement(s);}

The prompt() function prompts the user for an input within a pop-up box.

The alert() function pops-up a box with an alert message.

To perform concatenation or use variables within strings, use +. Example:

document.write("Your name is " + name + "!");

Conditional syntax follows the same pattern as every other programming language.

if (condition) {statement(s);} else {statment(s);}

document.write(); writes to the DOM and document.window(); will point to a URI.

document.getElementById(“id”) will search the DOM for the id.

Obfuscation

Posted August 27, 2008 at 12:46 pm in Programming | No Comments

This is not a tribute to the Starsiege: Tribes map. Code obfuscation is source code or intermediate code that is often intentionally scrambled to make it more difficult to read. The reason for this is to deter reverse engineering, disassembly, and decompilation, which may directly affect loss of intellectual property, ease of probing for application vulnerabilities and loss of revenue.

C, C++, and Perl are the easiest obfuscatable languages. There are many varieties of interesting obfuscations ranging from simple keyword substitution, use/non-use of whitespace to create artistic effects, clever self-generating or heavily compressed programs, or programs that are valid and operate similarly in multiple programming languages.

From a security standpoint code obfuscation creates a dilemma, especially for preventing XSS attacks. Dynamic code obfuscation techniques, which basically scramble malicious code in a different way each time a new visitor enters the malicious website, were developed in response to security vendors’ efforts to detect encrypted malicious code.

By obfuscating the malicious code, attackers are able to bypass signature-based solutions such as URI filtering, IDS/IPS, and anti-virus. This prevents a problem for code inspection which attempts to validate user inputs. Many phishing campaigns employ code obfuscation by obfuscating the malicious URI the user must access to avoid suspicion.

Dynamic obfuscation techniques allow visitors of a malicious site to receive a different instance of the obfuscated malicious code, based on random functions and parameter name changes. For each piece of obfuscated code, there would need to exist a signature using signature-based solutions to prevent dynamic obfuscation techniques. This would require an immense amount of time and research and as soon as a signature is ready to be implemented, the malicious code would have already mutated numerous times.

A suggested defensive measure is to use real-time code inspection, which analyzes and understands the code embedded within web content on-the-fly before it reaches the end users. Real-time code inspection would be able to break the code up into small segments, regardless of the code source, for inspection and action prior to execution of the code on network resources.

If you would like to experience an example of code obfuscation with Perl, try this code:

@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print

Compile and run from your shell for an interesting message.

Understanding the Kernel

Posted August 22, 2008 at 12:41 pm in Programming | No Comments

The kernel is a program that constitutes the central core of a computer operating system. It has complete control over everything that occurs in the system.

The kernel is the first part of the operating system to load into memory during system startup, and it remains there for the entire duration of the computer session because its services are required continuously.

The kernel code is usually loaded into a protected area of memory due to its critical nature. This prevents it from being overwritten by other, less frequently used parts of the operating system or by application programs.

It provides basic services for all other parts of the operating system, typically including memory management, process management, file management and I/O (input/output) management.

The contents of a kernel vary considerably according to the operating system, but they typically include:

  1. A scheduler, which determines how the various processes share the kernel’s processing time (including in what order).
  2. A supervisor, which grants use of the computer to each process when it is scheduled.
  3. An interrupt handler, which handles all requests from the various hardware devices that compete for the kernel’s services.
  4. A memory manager, which allocates the system’s memory addresses among all users of the kernel’s services.

Reference: The Linux Information Project

Page 2 of 3123