mardi 26 mars 2019

how to connect with AD

 public bool IsAuthenticated(string domain, string username, string pwd, string request)
        {
            bool isAuthenticated = false;
            string domainAndUsername;

            if (!string.IsNullOrWhiteSpace(domain))
            {
                domainAndUsername = domain + @"\" + username;
            }
            else
            {
                domainAndUsername = username;
            }

            _Log.Info("Parameters :");
            _Log.InfoFormat("Username. : {0}", domainAndUsername);
            _Log.InfoFormat("Path......: {0}", _path);

            DirectoryEntry entry = new DirectoryEntry(_path, domainAndUsername, pwd);

            if (entry == null)
                _Log.Error("No Directory Entry !!!");

            _Log.Info("DirectoryEntry informations :");

            _Log.InfoFormat("- AuthenticationType. : {0}", entry.AuthenticationType);
            _Log.InfoFormat("- Path............... : {0}", entry.Path);

            try
            {
                //Bind to the native AdsObject to force authentication.
                object obj = entry.NativeObject;

                _Log.Info("User search ...");

                DirectorySearcher search = new DirectorySearcher(entry);

                search.Filter = String.Format(request, username);

                _Log.InfoFormat("Filtering : {0}", search.Filter);

                search.PropertiesToLoad.Add("cn");

                _Log.InfoFormat("Properties loaded : {0}", string.Join(", ", search.PropertiesToLoad));

                SearchResult result = search.FindOne();

                if (result != null)
                {
                    _Log.InfoFormat("Result found : {0}", result.ToString());
                    isAuthenticated = true;
                }
                else
                {
                    _Log.Warn("No results !");
                }
            }
            catch (Exception ex)
            {
                _Log.Error("LDAP authentication error", ex);
                throw new Exception("Error authenticating user : " + username + ", pwd : " + new String('*', pwd.Length) + ", domain : " + domain + ", request : " + request);
            }

            return isAuthenticated;
        }

dimanche 22 novembre 2015

share your wifi with notepad

share your wifi with notepad :

-create a file .bat
-copy those lines
netsh wlan set hostednetwork mode=allow ssid=XXXX key=XXXXPSWD
netsh wlan start hostednetwork

-run  the file as administrator

jeudi 15 janvier 2015

operator i bet you never heard about


I can bet that you never heard about this operator on c# development but it's nice to know anyway:

operator =&

usually used in logical statement which is equivalent to x&=y -------> x& (y=x)

The left-shift operator (<<) 

shifts its first operand left by the number of bits specified by its second operand (always int )

exemple : i << 1---------->0x2

Operator >>= 
is equivalent to x >>= y---------> x = x >> y


Operator  x /= y
is equivalent to x /= y---------> x = x / y





samedi 3 janvier 2015

Dynamically changing searches based on the given parameters

It is very common in information systems to have functions where the users are able to search the data by selecting freely among many possible criterias. When you implement such a function with SQL Server there are two challenges: to produce the correct result and have good performance. Here few option i found:

Option 1: Using IF statements

IF @ClientNum IS NOT NULL
SELECT ... FROM CLients WHERE ClientNum = @ClientNum
ELSE IF @NumMatric IS NOT NULL
SELECT ... FROM Client WHERE NumMatric= @NumMatric
ELSE IF @Clientname IS NOT NULL
SELECT TOP 100// This is to have only few client and not all of them
FROM Client
WHERE clientName LIKE @clientName + '%'
ORDER BY clientName
ELSE
RAISERROR('No client found!')

Option 2:Using OR
If you don't like the multiple IF statements:

SELECT TOP 100
FROM Client
WHERE (ClientNum = @ClientNum AND @ClientNum IS NOT NULL) OR
(NumMatric = @NumMatric AND @NumMatric IS NOT NULL) OR
(Clientname LIKE @Clientname + '%' AND @Clientname IS NOT NULL)
ORDER BY Clientname

Option 3: Using Dynamic SQL
Here we assuming that OPTION (RECOMPILE) works like it does in SQL 2008 SP2, SQL 2008 R2
CREATE PROCEDURE ClSearch
@ClientName varchar(25) = null,
@ClientNum varchar(25) = null,
@ClientMatrix varchar(25) = null
AS
BEGIN
SELECT *
FROM Client
WHERE
(@ClientName IS NULL OR (ClientName = @ClientName ))
AND (@ClientNum IS NULL OR (ClientNum = @ClientNum ))
AND (@ClientMatrix IS NULL OR (ClientMatrix = @ClientMatrix ))
OPTION (RECOMPILE)
END


PS: Since the query is recompiled every time, you get a query plan that is optimised for the exact search conditions at hand. But if the search routine is called with high frequency, the recurring compilation may cause an overload on the server.

Handling Multi-valued Parameters:

To handel Multi-valued parametre the best way is to use intlist_to_tbl is a function  that cracks a comma-separated list into table ex:
AND (ClientMatrix IN (SELECT MatrixTabClient FROM intlist_to_tbl(@ClientMatrix))
OR @ClientMatrix IS NULL)


In the end i want to say changing searches based on the given parameters is a complicated subject and i always recommend to use index this will gain a lot of performance in the result.

vendredi 5 septembre 2014

How to hack your Girlfriend 's computer

Ok first of all this doesn't have any relationship with csharp or whatever .Net code you will think about.

Today i feel about teach you guys something cool to do , we going to learn how to hack to your Girlfriend 's computer so be careful and do exactly what i tell you to do.

OK HACKERS  ... ARE YOU READY !



Step 1: Migrate the Meterpreter

Before we start our keylogger, we need to migrate the Meterpreter to the application or process we want to log the keystrokes from. Let's check to see what processes are running on the victim system by typing:
meterpreter >ps


Notice in the screenshot above that we have a listing of every process running on the victim system. We can see about 1/3 of the way down the process listing with a Process ID (PID) of 912, the Notepad application is open and running.


Let's migrate to that process and capture any keystrokes entered there. Type:
meterpreter > migrate 912
You can see from the screenshot that Meterpreter responds that we have migrated successfully,


Step 2: Start the Keylogger

Now that we have migrated the Meterpreter to the Notepad, we can embed the keylogger.
Metasploit's Meterpreter has a built-in software keylogger called keyscan. To start it on the victim system, just type:
meterpreter> keyscan_start
With this command, Meterpreter will now start logging every keystroke entered into the Notepad application.

Step 3: Write a Short Note on the Victim System

Let's now move to our victim system and write a short note to make sure it works.


As you can see in screenshot above, Cheatah has written a short note to Stud, asking him to come visit while her boyfriend is gone. All of these keystrokes are being captured by our keylogger providing us with evidence of her cheating heart (or some other organ).

Step 4: Recover the Keystrokes

Now, let's go back to our system with Meterpreter running on Metasploit. We can now dump all of the keystrokes that were entered on Cheatah's computer. We simply type:
meterpreter> keyscan_dump


As you can see, every keystroke has been captured including the tabs and end of line characters. Now you have the evidence on Cheatah!

I hope you like this article and you enjoyed ... cheers

PS :Lucile you can you use this on your BF too ;)



Auto-launching apps in Windows phone

You can use file and URI associations in Windows Phone 8 to automatically launch your app when another app launches a specific file type or URI scheme. When launched, a deep link URI is used to send the file (a reference to the file) or URI to your app. You can also use the association launching API to launch another app in the same way. This topic describes file and URI associations, and how you can use them in your app.



File associations


File associations allow your app to automatically launch when the user wants to open a particular file. That file could come from a variety of sources including, but not limited to:
  • an email attachment
  • a website via Internet Explorer
  • a Near Field Communications (NFC) tag
  • another app from the Store
To register for a file association, you must edit WMAppManifest.xml using the XML (Text) Editor. In Solution Explorer, right-click the WMAppManifest.xml file, and then click Open With. In the Open With window, selectXML(Text) Editor, and then click OK.

<Extensions>
   <FileTypeAssociation Name="Windows Phone SDK test file type" TaskID="_default" NavUriFragment="fileToken=%s">
       <Logos>
           <Logo Size="small" IsRelative="true">Assets/sdk-small-33x33.png</Logo>
           <Logo Size="medium" IsRelative="true">Assets/sdk-medium-69x69.png</Logo>
           <Logo Size="large" IsRelative="true">Assets/sdk-large-176x176.png</Logo>
       </Logos>
       <SupportedFileTypes>
         <FileType ContentType="application/sdk">.sdkTest1</FileType>
         <FileType ContentType="application/sdk">.sdkTest2</FileType>

       </SupportedFileTypes>
   </FileTypeAssociation></Extensions>

Listening for a file launch

When your app is launched to handle a particular file type, a deep link URI is used to take the user to your app. Within the URI, the FileTypeAssociation string designates that the source of the URI is a file association and the fileToken parameter contains the file token. For example, the following code shows a deep link URI from a file association.

namespace sdkAutoLaunch
{
    class AssociationUriMapper : UriMapperBase
    {
        private string tempUri;

        public override Uri MapUri(Uri uri)
        {
            tempUri = uri.ToString();

            // File association launch
            if (tempUri.Contains("/FileTypeAssociation"))
            {
                // Get the file ID (after "fileToken=").
                int fileIDIndex = tempUri.IndexOf("fileToken=") + 10;
                string fileID = tempUri.Substring(fileIDIndex);

                // Get the file name.
                string incomingFileName =
                    SharedStorageAccessManager.GetSharedFileName(fileID);

                // Get the file extension.
                string incomingFileType = Path.GetExtension(incomingFileName);

                // Map the .sdkTest1 and .sdkTest2 files to different pages.
                switch (incomingFileType)
                {
                    case ".sdkTest1":
                        return new Uri("/sdkTest1Page.xaml?fileToken=" + fileID, UriKind.Relative);
                    case ".sdkTest2":
                        return new Uri("/sdkTest2Page.xaml?fileToken=" + fileID, UriKind.Relative);
                    default:
                        return new Uri("/MainPage.xaml", UriKind.Relative);
                }
            }
            // Otherwise perform normal launch.
            return uri;
        }
    }
}

more info :
http://msdn.microsoft.com/library/windows/apps/jj206987(v=vs.105).aspx

Enjoy!




cool icons for windows phone 7 & 8

for all the people who looking for icons for any app for windows phone 8 & 7 this is a nice collection you may like:
http://www.geekchamp.com/icon-explorer/action-icons