- bits & pieces about software development HostingAbc Logo
Pages:01>>
If you've ever wondered how could you list all your usernames and passwords that are set on the 'Directory Security' tab on each website's properties (in inetmgr) then this small C# code snippet would be for you ..
Just a note: so far it seems that this code snippet works only on Windows Server 2003 - i have no ideea why doesn't it work on XP / Vista as well (don't care actually :) - i needed it for win 2003)...

C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
static void Main(string{} args)
{
    DirectoryEntry iisBase = new DirectoryEntry("IIS://localhost/W3SVC");
    PrintUserNameAndPass(iisBase);
}

private static void PrintUserNameAndPass(DirectoryEntry iisChild)
{
    String userName = null; 
    String password = null;
    
    if (iisChild.Properties{"AnonymousUserName"} != null)
    {
        userName = iisChild.Properties{"AnonymousUserName"}.Value as String;
    }
    if (iisChild.Properties{"AnonymousUserPass"} != null)
    {
        password = iisChild.Properties{"AnonymousUserPass"}.Value as String;
    }

    if (userName != null && password != null)
    {
        if (!userNames.Contains(userName))
        {
            byte{} passwordChars = ASCIIEncoding.ASCII.GetBytes(password);
            Console.WriteLine(String.Format("{0}\t{1}", userName, 
              System.Convert.ToBase64String(passwordChars)));
            userNames.Add(userName);
        }
    }

    foreach (DirectoryEntry newChild in iisChild.Children)
    {
        PrintUserNameAndPass(newChild);
    }

    iisChild.Dispose();
}


Update: Actually I've found out that the exception on Windows Vista was caused by the lack of IIS6 compatibility module. So I've just had to install this compatibility module from Windows features and everything works as expected.
created on: 7/2/2008 9:10 AM
tags:
IIS 6.0(1)
hits: 13
comments: (0)
created on: 6/27/2008 10:24 AM
tags:
humor(1)
hits: 30
comments: (0)
C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
namespace ConsoleApplication1
{
    using System;
    using System.Text;
    using System.Net;
    using System.Net.Sockets;

    public class ConsoleApplication1
    {
        protected const int PJL_PORT = 9100;
        protected static string message = "Ready";

        public static int Main(string{} args)
        {
            if (!ParseArgs(args))
            {
                return -1;
            }

            IPEndPoint ipEndPoint;
            ipEndPoint = new IPEndPoint(Dns.Resolve(args{0}).AddressList{0}, PJL_PORT);

            Socket socket;
            socket = new Socket(
                              AddressFamily.InterNetwork,
                              SocketType.Stream,
                              ProtocolType.Tcp
                           );

            socket.Connect(ipEndPoint);

            byte{} sendData;
            string sendString;

            sendString = String.Format(
                      "\x1B%-12345X@PJL RDYMSG DISPLAY = \"{0}\"\r\n\x1B%-12345X\r\n",
                      message
                 );

            sendData = Encoding.ASCII.GetBytes(sendString);

            socket.Send(sendData, sendData.Length, 0);

            socket.Close();

            return 0;
        }

        protected static bool ParseArgs(string{} args)
        {
            if (args.Length != 2)
            {
                Console.WriteLine("set printername and message");
                return false;
            }

            if (args{1}.Length > 16)
            {
                Console.WriteLine("Message must be <= 16 characters");
                return false;
            }

            message = args{1};

            return true;
        }
    }
}

Forrás: http://vortexhunter.blogspot.com/2008/06/c-hp-laserjet-fun-fun-fun.html
created on: 6/25/2008 3:00 PM
tags:
General(11)
hits: 38
comments: (0)
C#
1
2
3
4
5
6
7
8
9
10
if (!s_inited)
        {
            lock (s_initLock)
            {
                if (!s_inited)
                {
                    s_inited = true;
                }
            }
        }
created on: 6/23/2008 3:03 PM
tags:
hits: 39
comments: (4)
Yet another simple logrotate script. If you hate the original one, just use this one ;)

Download file: logrotate.zip
created on: 6/10/2008 10:01 AM
tags:
linux(3)
hits: 71
comments: (0)
If you have an open 22 port (SSH) on your machine, and you are interested in blocking all the IP addresses that try to bruteforce your password then this script is for you ;) .
As I really don't like using custom ports for any service if there is an other solution, I had to come up with this solution instead. In addition to this script there is also private/public key authentication turned on for dropbear (the ssh server for wl500gp) - however it's annoying seeing lots of invalid connections in auth.log :) .

How to use it:
The script should be started from crontab, and runs for at most 5 seconds for small authentication log files, so i start this script in each 15 minutes ;) .
You should change the path for all the files used in this script to match your system - then everything should work as expected.

you have questions - shoot me ;)
Download files: bruteForce.zip

The files included in the zip contain the ip addresses that tried to brute force my system. Keep the list if you want ;)
created on: 6/10/2008 9:05 AM
tags:
linux(3)
router(2)
wl500g(2)
hits: 76
comments: (0)
Recently I've bought an Asus WL500GP router. Just very quickly the list of it's features:

[*] there are custom linux based firmares available for it
[*] has 2 usb ports (supports USB hub, external hard drives, web cameras, card readers, usb sound cards)
[*] high quality design ;)


(i've opened my router and added a small 4GByte microdrive so it has a permanent harddisk attached. WARNING: this voids its warranty !!!)


It has a really wide package support, and can be used as a real NAS with multiple harddisks.

Anyways - stay tuned: I'm going to publish a few tutorials on how to do stuff with the router ;)
created on: 6/5/2008 12:05 PM
tags:
linux(3)
router(2)
wl500g(2)
hits: 111
comments: (3)
created on: 2/25/2008 11:52 PM
tags:
General(11)
hits: 313
comments: (0)
I have a Vista Home Premium edition running on a Toshiba 300-11V laptop with 2G memory + a Core 2 Duo 1.8GHz CPU. I would say that it's acceptable. Not fast, but acceptable; which is all right because i always knew it requires more resources that Windows XP.
However these days I started playing around with a couple of USB pen drives to see if it really helps in Vista's performance if you plug in one of those...
First of all I was really surprised to see that a bunch of the usb flash cards were not fast enough for Vista. There is a good article on Wikipedia (http://en.wikipedia.org/wiki/ReadyBoost) which explains what kind of speed characteristics must the flash drive meet.

So finally after testing a couple of these usb flash drives and an SD memory card too I've decided to go for a 4GB SD flash card as my laptop has a built in SD card reader ...

It was a bit expensive - i might have as well bought a 1GB DDRAM module for the laptop, however I think that the performance gain with the ReadyBoost technology using the 4GB flash can be much higher then with the additional 1GB memory ...

A final word on how this whole stuff works: Windows needs files and data. These files and data when you have several programs in memory are paged to the pagefile obviously. Now the trick is that when Vista needs some items from the pagefile that were previously cached on the flash drive it will read them from the flash drive. Simple. The same is happening with some DLLs that are used frequently in the operating system - they are cached on the flash drive.
The reason why this can work is that a flash memory can be much faster on random memory access than a hard disk. I mean when you load 2 files simultanously from your hard drive the disk's head will move from one place to the other and the whole read operation will be damn sloooow - this is where Vista's ReadyBoost technology kicks in and ensures that the data is read more quickly from the flash drive if already cached ...

While I have to admit that using this memory card the performance gain in my case it's not that extreme - it is still visible, and I'm really happy I can now use my built-in SD memory card reader which until now was empty :) ...
created on: 2/3/2008 12:11 AM
tags:
General(11)
Vista(2)
hits: 351
comments: (0)
Windows Vista Home Premium does have a built in remote desktop. You can see it by starting a remote assistance session ... It's the same thing. Now the question is whether it is possible to start the service somehow to use this built-in functionality for accessing your PC remotely every time withouth starting remote assistance.

The answer is YES. It is possible. And this zip file is the answer: termsrv.zip.
Warning: I've downloaded this zip file from an other page (http://portal.tonychan.org/Default.aspx?tabid=58&EntryID=123) and I'm not responsible for any kind of loss that eventually might happen if you are using this zip file.
created on: 11/14/2007 3:56 PM
tags:
General(11)
Vista(2)
hits: 1136
comments: (0)
These days I was so excited about IPSec that I really had to find out how the encryption and authentication works :) ... Actually this is a very usefull feature as it prevents anybody who is not authenticated to access a service on your server - and this is done on the level of the IP protocol. That is the hacker won't be allowed to run a brute force attack on your RDP protocoll because he won't actually be able to communicate with the RDP server unless he is previously authenticated. So let me explain how this works...

As I said IPSec enables authentication and encryption. The first step - the authentication can be done in 3 different ways: using a certificate issued by a trusted certification authority, using active directory or using a passphrase. I've decided to choose the certificate-based-authentication as i don't have active directory and the passphrase seems to easy for me to crack with an network sniffer :) ...
Let me show you the way this certificate based authentication works:

First of all the server is configured to trust only clients that have a special certificate issued by a certificate authority - this means that the server does trusts a range of computers not only one, but actually every computer that has a certificate issued by the configured Certificate Authority ( probably not everybody will by certificates from verisign, comodo or godaddy :) so be aware that if you issue your own certificates that you have to explicitely trust the certificate authority both on the client and the server ).

That said, just be sure that:
1. the special type of IPSec ceritifacte is requested from the certification authority
2. the certificate authority is trusted on each machine

What we have to understand is that on every client that participates on secure IP communication an IPSec policy has to be created and activated. It's not enough just to get the certificate on the client machine - we need to create an IPSec policy on the client as well and we have to activate this policy otherwise IPSec won't be used...

Now on the other hand we can enable encryption on the authenticated traffic. If we have a telnet server which is well known by it's unsafe way of sending clear text username & password over the network - we can encrypt this traffic and nobody will ever be able to see your sensitive information ...

So here are 2 screenshots of the relevant IPSec configuration windows, check them out, and there is an MSDN article as well which explains in detail how to configure IPSec with a certificate: http://support.microsoft.com/kb/253498

created on: 11/2/2007 12:43 PM
tags:
General(11)
hits: 437
comments: (0)
Recently my list of purchased software was extended with Microsoft Windows Server 2003 Web Edition - which is the low price version of Windows Server 2003 Standard. Until SP2 was released the Web Edition was capable of handling 2GBs of memory but Microsoft decided with SP2 that a web server might need the use 4GBs of memory :) so with the low price they've included support for 4GBs... Unfortunatelly what they did NOT include is the Windows Firewall. I'm not really sure why would Microsoft consider that a web server needs less security - probably the low price means lower security at Microsoft :S ...

So I had to make a decision whether to install the free firewall from Comodo or to use IPSec. While IPSec was not designed specifically for this task, it can be used very well and it reminds me of iptables or ipchains on linux where I had absolute control of how my IP traffic is filtered.

So the first step was to launch Start->Administrative Tools->Local Security Policy where we can find IP Security Policies.


My advice is to play with these settings ONLY ON THE CONSOLE as there is a really good chance that we are going to face the unlikely event of locking out ourselves if we are logged in remotely through terminal services :) ... so just carefully :).
Now what we have to understand is that IPSec can match types of IP traffic - based on protocol, traffic direction and traffic source/destination. For instance let's say that an administrator would like to allow outsiders to use the locally installed SMTP server. This means that we have to identify the INCOMING traffic on port 25 and to ALLOW this traffic. This is achieved by creating a filter set rule that permits the traffic for a filter that matches traffic on TCP destination port 25 where the source IP address is anything and the destination is 'my ip address' :)
Basically this is what you have to do for each type of traffic you want to allow, but here are some screenshots, check them out, and what you should really do is to download from the bottom of this article my exported IPSec policies and import them to your computer and have an insight look on the filters.


One last word on IPSec policies: they are enabled on the machine only after right clicking the policy and choosing "Assing" from the context menu and that they can be modified from the command line as well using the "netsh ipsec static ..." commands.
And finally here are my IPSec policies, hope it helps you out hours of googling ;) ...

Download: FirewallWithIPSec.zip

Update {10/25/2007} : in the Enhanced version of Web Edition there IS a firewall. I've just installed the bits received from my MS reseller - and Web Edition does have the Windows Firewall. However I still consider that IPSec is better than Windows Firewall as there is no possibility to filter outgoing traffic with WF.
created on: 10/24/2007 6:15 PM
tags:
General(11)
hits: 477
comments: (0)
If the LINQ runtime just thrown an exception similar to this one to your face :) then you should know that you just forgot to set a primary key in your table.
Also don't forget to update your data class in the .net project model as well ;) as the table's definition has changed.
created on: 10/19/2007 11:21 PM
tags:
LINQ(2)
hits: 1014
comments: (2)
I was wondering how to save small bitmaps programmatically of websites so I can show a gallery of these web pages on an ASP.Net page.

Obviously the first step in achieving it is to use a webbrowser control in .NET and to navigate to the specified webpage.
The second step would be to copy the image from the web browser's window to our own Bitmap using the BitBlt WinAPI method and the last step would be to save this bitmap somewhere on the file system or maybe a database.

So let's see the method which captures the content of a web browser window and saves it to a Bitmap object:

C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
private Bitmap CaptureBrowserImage(WebBrowser browser)
{
    Bitmap resultBitmap = new Bitmap(browser.Width, browser.Height);
    Graphics g = Graphics.FromImage(resultBitmap);

    IntPtr hdcSrc = GetWindowDC(browser.Handle);
    IntPtr hdcDest = g.GetHdc();

    BitBlt(hdcDest, 0, 0, browser.Width, browser.Height, hdcSrc, 0, 0,
        (uint)TernaryRasterOperations.SRCCOPY);

    g.ReleaseHdc(hdcDest);
    ReleaseDC(browser.Handle, hdcSrc);

    return resultBitmap;
}


It might also be possible to use the StretchBlt WinAPI method to generate a smaller image, but I just wanted to save the image as it is - later on I will be able to generate thumbnails out of the saved images if I want to.

(big thanks to András for the ideea and help on using BitBlt)
created on: 10/5/2007 4:15 PM
tags:
General(11)
hits: 443
comments: (0)
Well, it's about time ! I think it was really just a question of time that this step is made and the fact that this step is going to be taken with the release of VS2008 it's just pure marketing :)

Anyways, it's really great to have it :) ! Imagine stepping into StringBuilder's own methods or stepping through the LosFormatter class in Visual Studio :) !!
Some say that now it's the end of Lutz Roeder's Reflector but I actually consider Reflector better then the MSDN Help files - in quick finding functionality in .NET ...

Source: Scott Guthrie's blog
created on: 10/3/2007 11:35 PM
tags:
General(11)
hits: 411
comments: (0)
How to do a simple sorted list in C# ? Here it is:

C#
1
2
3
4
5
6
7
8
class MySortedList<T> : List<T>
{
    new public void Add(T item)
    {
        int index = BinarySearch(item);
        Insert(index >= 0 ? index : ~index, item);
    }
}

(andrás & moszi coop)
created on: 9/28/2007 5:12 PM
tags:
General(11)
hits: 462
comments: (1)
I was wondering how to easily parse a simple xml structure and build an object list from it, and here it is a solution with LINQ to XML:

C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
XDocument xd = XDocument.Parse(@"
    <xml>
        <book Author=""Moszi"" Title=""First book"" />
        <book Author=""Eszto"" Title=""Second book"" />
        <book Author=""Eszto"" Title=""Second book - 2nd edition"" />
    </xml>");

var q = from c in xd.Descendants()
        where c.Name == "book" && c.Attribute("Author").Value == "Eszto"
        select new { Author = c.Attribute("Author").Value,
                     Title = c.Attribute("Title").Value
        };


foreach (var qValue in q)
{
    Console.WriteLine(qValue);
}


What we can notice here is the usage of c.Attribute("Title") - while the XElement.Attribute() take an XName as a parameter and the correct form would be c.Attribute(XName.Get("Title")) the framework designers have come up with an operator to make our life easier :) ...
created on: 9/14/2007 12:22 PM
tags:
LINQ(2)
hits: 425
comments: (0)
A long run - but never finished :) - project that I'm doing is a rule framework plugin for Outlook - FolderRules.NET - and as Orcas has some promising new features on VSTO integration I decided to convert my plugin to .NET 3.5.

The first we can notice that opening the New Project dialog we choose from a new suite of Office 2007 project templates - all based on the .NET framework 3.5:

. The source code that is generated by this wizard is fairly straightforward and we simply just can write our initialization code to the ThisAddin_Startup method.

In this example I'm telling Outlook that I need a new Option Page on the
Tools->Options dialog and that I need a new menu item on the context menu that appears on each folder:
C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
this.Application.OptionsPagesAdd += pages => 
    pages.Add(new UserControl1(), "Folder Rules");

this.Application.FolderContextMenuDisplay += 
    delegate(Office.CommandBar commandBar, Outlook.MAPIFolder folder)
{
    CommandBarButton newButton = commandBar.Controls.Add(
        MsoControlType.msoControlButton,
        missing, missing, missing, missing) as CommandBarButton;
    newButton.Caption = "Folder Rules";
    newButton.FaceId = 473;
    newButton.Style = MsoButtonStyle.msoButtonIconAndCaption;
    newButton.Click += delegate(CommandBarButton control, ref bool cancelDefault)
    {
        MessageBox.Show("Test2");
    };
};

As you can see the code instanciates a new UserControl1 class - this will be added on a new tab page on the Options dialog.
However it seems that creating a simple WPF control and exposing it to COM is not possible because the System.Windows.UserControl class is not ComVisible - so the trick here what we should do to have a XAML enabled control in the Options dialog is to use an ElementHost on our Windows Forms control which in turn will host a XAML enabled control.

Also an other thing we should do is to make our control to look like Outlook's control; so for this we should paint our control's background using the VisualStyleRenderer class like in the following code example:
C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
VisualStyleRenderer renderer;
VisualStyleElement element = VisualStyleElement.Tab.Body.Normal;

public UserControl1()
{
    InitializeComponent();

    if (Application.RenderWithVisualStyles &&
        VisualStyleRenderer.IsElementDefined(element))
    {
        renderer = new VisualStyleRenderer(element);
    }
}

protected override void OnPaint(PaintEventArgs e)
{
    if (renderer != null)
    {
        renderer.DrawBackground(e.Graphics, this.ClientRectangle);
    }

    base.OnPaint(e);
}

Enjoy :)
created on: 9/12/2007 5:39 PM
tags:
WPF(2)
VSTO(1)
hits: 476
comments: (0)
Finally I've integrated in my blog engine a syntax highlighter that it's for my taste :) : Wilco Bauwer's SyntaxHighlighter for .NET. It's a really easy to use, easy to integrate control - probably that's why some guys refer to it as a 'must download' control :).

I've tested a JavaScript based syntax highlighter as well (http://code.google.com/p/syntaxhighlighter/) but actually I like the ideea of server side building (&caching the result) of the code that has to be highlighted...
created on: 9/12/2007 5:05 PM
tags:
General(11)
hits: 500
comments: (0)
Today I've downloaded Expression Blend to see it's capabilities and I really hope that some or all of it's functionality will be included in Visual Studio 2008 as well.

I've just created an extremely simple application with 2 XAML forms which took me aproximately 5 minutes. Here are the XAML codes for the 2 windows:
XML
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="UntitledProject1.Window1"
x:Name="Window"
Title="Window1"
Width="230" Height="157">

<Grid x:Name="LayoutRoot">
	<Button Margin="54.751,41.305,63.651,51.606" 
	Content="Button" RenderTransformOrigin="0.494,0.483" 
	x:Name="button1" >
		<Button.RenderTransform>
			<TransformGroup>
				<ScaleTransform ScaleX="1" ScaleY="1"/>
				<SkewTransform AngleX="0" AngleY="0"/>
				<RotateTransform Angle="30"/>
				<TranslateTransform X="0" Y="0"/>
			</TransformGroup>
		</Button.RenderTransform>
	</Button>
</Grid>
</Window>

Login.xaml (only a part of it):
XML
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<Label Content="Password:" Margin="10,0,0,44" 
RenderTransformOrigin="0.5,0.5" HorizontalAlignment="Left" 
VerticalAlignment="Bottom" Width="103.855" Height="22">
	<Label.RenderTransform>
		<TransformGroup>
			<ScaleTransform ScaleX="1" ScaleY="1"/>
			<SkewTransform AngleX="0" AngleY="0"/>
			<RotateTransform Angle="15"/>
			<TranslateTransform X="0" Y="0"/>
		</TransformGroup>
	</Label.RenderTransform>
</Label>
<PasswordBox Margin="104,0,90,42" RenderTransformOrigin="0.5,0.5" 
VerticalAlignment="Bottom" Height="22">
	<PasswordBox.RenderTransform>
		<TransformGroup>
			<ScaleTransform ScaleX="1" ScaleY="1"/>
			<SkewTransform AngleX="0" AngleY="0"/>
			<RotateTransform Angle="-11.241"/>
			<TranslateTransform X="0" Y="0"/>
		</TransformGroup>
	</PasswordBox.RenderTransform>
</PasswordBox>
Now the 2 XAML forms look like this:

One thing that caught my attention is that when writing the delegate to open the login form a new type of event handler has to be specified for the button click event:
C#
1
2
3
4
5
this.button1.Click += new RoutedEventHandler(
  delegate(object sender, RoutedEventArgs args)
{
    new Login().ShowDialog();
});
I will definitely have a more in-depth look into this application; it seems really promising.
created on: 9/3/2007 10:44 AM
tags:
XAML(1)
WPF(2)
hits: 486
comments: (2)
Pages:01>>
add linkThe last comments:moszidev says:Venemo: it is at System.Web.Configuration.HttpConfigurationSystem.UseHttpConfigurationSystem moszidev says:dumb, ... no wonder your name is dumb :) ... i more or less expected these type of answers :) - trust me, i know the double locking design pattern :) ... but it seems that you don't really know for what the locking is needed ;) ...dumb says:this is called double locking: http://en.wikipedia.org/wiki/Double_checked_locking_patternVenemo says:Where did you find this in the framework?moszidev says:just found out that the maximum transfer rate on USB or UTP for this router is 3.5MBytes/sec. (that is 28MBit / sec)[br] So if you have a connection speed higher than this, it will not be fully used for sure.moszidev says:yepp, i know dd-wrt as well ;) - actually what i liked in oleg's firmware is that he didn't change the web ui ( which actualy i turned it off completely now ... ) - he just added new functionality to it.Kornel Javor says:If you're interested in custom firmwares, you should try dd-wrt too. As far as I know, your gadget is supported. Take a look at http://dd-wrt.com Dozens of new features were revealed after it was deployed to my Linksys and turned to a thousand do
Copyright (C) 2007, Molnar Szilveszter m@il me