Tuesday, September 21, 2010

Make your application extensible with Reflection

Public Shared Function LoadAll(Of T)() As List(Of T)
Dim services As New List(Of T)()

For Each type As Type In Assembly.GetCallingAssembly().GetTypes()
If type.IsSubclassOf(GetType(T)) AndAlso Not type.IsAbstract AndAlso Not type.IsInterface Then
services.Add(DirectCast(Activator.CreateInstance(type), T))
End If
Next

Return services
End Function

Monday, September 20, 2010

Start a Process as a Different User - developer Fusion

Start a Process as a Different User - developer Fusion: "Function ConvertToSecureString(ByVal str As String)

Another usefull code snippet
Credits go to Peter Rekdal Sunde at developerfusion.com

Function ConvertToSecureString(ByVal str As String)
Dim password As New SecureString
For Each c As Char In str.ToCharArray
password.AppendChar(c)
Next
Return password
End Function
Sub Main()
dim username as string = "Administrator"
dim password as SecureString = ConvertToSecureString("my password")
dim domain as string = Nothing
dim filename as string = "notepad.exe" ' %SYSTEMROOT%\system32
Try
System.Diagnostics.Process.Start(filename,username, password, domain)
Catch ex As Win32Exception
MessageBox.Show("Wrong username or password.", _
"Error logging in as administrator", MessageBoxButtons.OK, _
MessageBoxIcon.Error)
End Try
End Sub

Deep clone an object in .NET - developer Fusion

Deep clone an object in .NET - developer Fusion

A code snippet that could be very useful, so I though I'd share this with you...

Credits go to James Crowley at developerfusion.com


There are two types of object cloning; deep and shallow.
A shallow clone creates a new instance of the same type as the original object, with all its value-typed fields copied. However, the reference type fields still point to the original objects; and so the "new" object and the original reference to the same object. On the other hand, a deep clone of an object contains a full copy of everything directly or indirectly referenced by the object - and so you get a "true" copy.
One of the easiest ways to deep-copy an object is to serialize the object into memory and de-serialize it again - although this does require the object graph to be serializable. Here's a handy code snippet to do this:
public static object CloneObject(object obj)
{
using (MemoryStream memStream = new MemoryStream())
{
BinaryFormatter binaryFormatter = new BinaryFormatter(null, 
new StreamingContext(StreamingContextStates.Clone));
binaryFormatter.Serialize(memStream, obj);
memStream.Seek(0, SeekOrigin.Begin);
return binaryFormatter.Deserialize(memStream);
}
}
You could then implement the ICloneable interface on your object like so:
public class MyObject  : ICloneable {
public object Clone()
{
return ObjectUtility.CloneObject(this);
}
...
}

Thursday, September 16, 2010

InCtrl 5 Application Analysys Tool – Download and Enjoy | Simon Todd's Free Technical Blog!

InCtrl 5 Application Analysys Tool – Download and Enjoy | Simon Todd's Free Technical Blog!


InCtrl 5 is an amazing application, it is very simple to use and simple in the results it give but it is very very powerful. InCtrl 5 looks for all of the differences before and after an application is installed.


InCtrl 5 is a great tool for those that build XPe (XP Embedded) development, Application Virtulisation or Terminal Services/Citrix. It allows you to look and see what is added into the Registry and file system, it also shows you what was edited and changed during the installation the the application you are testing.
I have used this product to components XPe applications, work out where an application tries to install its self on a Terminal Server and to double check the tools for Application Visualisation.
A really good an useful tool.

Tuesday, September 14, 2010

Printer Driver Generator 1.3.0.0 | Novell User Communities

Printer Driver Generator 1.3.0.0 | Novell User Communities: "Printer Driver Generator 1.3.0.0"


Nice little tool to regenerate a printer INF file...





license:
Free
This is a small tool that I wrote out of need. I do believe that this tool may be of use to others, but it's still in beta phase, and I need feedback from users, Please :-)
Problem:
I have a printer that did not come with an INF-based printer driver,but instead with a setup.exe-based driver / or integrated with Windows. I don't run iPrint, but only Point-And-Print, or NDPS. How do I distribute this driver?
Answer:
Install this program on your PC, and run PDrvGen.exe, select the printer, and select "Generate".An INF-based driver will now be generated!
What's new in version 1.3.0.0:
  • Gray Cash from the USA had a small, but nice request, that I preserved the version info in the driver, if it was present in the origen driver.
    That way, troubleshooting would be a lot easier to do.
PDrvGen will now extract and save the Driver Version info"
What's new in version 1.2.0.0:
  • Theo Pluym found an HP Driver that wasn't written that well, since it didn't liked a space between the parameters. Since I figured, that other drivers might suffer from the same problem, I corrected PDrvGen to generate inf-files without this.

    Download : PDRVGen.zip

Monday, September 13, 2010

Ghostcript PDF Reference & Tips — Milan Kupcevic

Ghostcript PDF Reference & Tips — Milan Kupcevic


Basic Usage
Convert PostScript to PDF:
gs -q -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=fileout.pdf \     filein.ps 
Merge/combine PDF and/or PostScript files:
gs -q -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=fileout.pdf \     filein.ps filein2.pdf 
Extract a page from a PostScript or a PDF document:
gs -q -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -dFirstPage=3 -dLastPage=3 \     -sOutputFile=fileout.pdf filein.ps 

Additional Options

PDF optimization level selection options

-dPDFSETTINGS=/screen   (screen-view-only quality, 72 dpi images) -dPDFSETTINGS=/ebook    (low quality, 150 dpi images) -dPDFSETTINGS=/printer  (high quality, 300 dpi images) -dPDFSETTINGS=/prepress (high quality, color preserving, 300 dpi imgs) -dPDFSETTINGS=/default  (almost identical to /screen) 

Paper size selection options

-sPAPERSIZE=letter -sPAPERSIZE=a4 -dDEVICEWIDTHPOINTS=w -dDEVICEHEIGHTPOINTS=h (point=1/72 of an inch) -dFIXEDMEDIA (force paper size over the PostScript defined size) 

Other options

-dEmbedAllFonts=true -dSubsetFonts=false -dFirstPage=pagenumber -dLastPage=pagenumber -dAutoRotatePages=/PageByPage -dAutoRotatePages=/All -dAutoRotatePages=/None -r1200 (resolution for pattern fills and fonts converted to bitmaps) -sPDFPassword=password

Thursday, September 9, 2010

Hackers Guide to Being Hacked: How “Bad Guys” Take Control, and How to Take it Back. - hacked, hackers, security, recovery, repair, attack

Hackers Guide to Being Hacked: How “Bad Guys” Take Control, and How to Take it Back. - hacked, hackers, security, recovery, repair, attack

I've found an interesting blog about preventing/dectecting an attack. So let's blog it, you never know when this will come in handy...

How to Recover from an Attack.


Find the Affected Machine(s).

In some cases, like the website hijack or the "attack page" example, you'll know which machine has been affected. In most cases, however, you're going to have to find it.

The best tool for figuring out which computer has been compromised is netstat. Netstat reveals all the incoming and outgoing connections on a computer, and is available on Linux, Windows, and Mac.

Methodically check all the computers in your network using one of the netstat commands below:

Windows
1:
netstat -an | find "ESTABLISHED"

Mac / Linux
1:
netstat -an | grep ESTABLISHED

This command will show you all the established connections to the computer. It will be fairly obvious which machine is infected when you find it. For example, a Linux server infested with an SSH scanner (a script that breaks into your network, then tries to break into everyone else's) will have tons of connections to other networks with a destination port of 22.

A spam relay will have tons of connections to everywhere with a destination port of 25.

An FTP brute force attacker will have tons of connections to destination port 21.

...and so on.

When you find a machine that you suspect has been infected, run the same command as above again, only this time leave out the n switch:

Windows
1:
netstat -a | find "ESTABLISHED"

Mac / Linux
1:
netstat -a | grep ESTABLISHED

This will allow the system to resolve the IP addresses previously shown to their rDNS equivalents. We're looking for a dead giveaway here: connections to foreign countries. When you see 17 connections from Romania, Russian, Taiwan or some other foreign country, and you are not in that country, it is a dead giveaway.

Lastly, run netstat a final time to find the offending processes:

Windows
1:
netstat -ao | find "ESTABLISHED"

Mac / Linux
1:
netstat -ap | grep ESTABLISHED

Write down the offending processes. We'll need this list later.


Blockade your Network.

By now, you should have already downloaded m0n0wall - as I mentioned, you should have a firewall in the prevention steps. A hardware firewall is your best friend in mitigating the effects of a hack attack. While we originally implement a hardware firewall to keep bad guys out, if you've been compromised, you have a duty to mitigate the damage you are doing by keeping the probes, scans, spam, and other garbage in.

Turn on the outbound firewall, and set it to disallow all outbound traffic except traffic with a destination port of 80 or 443. This allows you to keep surfing the web and access secure sites to get more help and information to recover from the attack, but it keeps all the spam (destination port 25), port scans (many different ports), DoS attacks (ping), BotNets (usually IRC ports), and other nasty stuff from being able to leave your network, which renders them effectively useless to the attacker.