Hack Forums
[.NET] GET Request + finding status code - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [.NET] GET Request + finding status code (/showthread.php?tid=5456133)

Pages: Pages 1 2


GET Request + finding status code - Egregious Jr. - Nov 6, 2016

How can I make GET request to the API and then save the HTTP status code?


* - Papa Cuda - Nov 6, 2016

Are you talking about banner grabbing, like with net cat or telnet?


* - Egregious Jr. - Nov 6, 2016

(Nov 6, 2016 02:13 PM)cudacore Wrote:  Are you talking about banner grabbing headers?
Basically, I want to do something like

GET http://api.domain.com/profiles/<input>;

Then save the code it returns (403, 404, etc)


* - Papa Cuda - Nov 6, 2016

(Nov 6, 2016 02:14 PM)Zach Wrote:  Basically, I want to do something like

GET http://api.domain.com/profiles/<input>;

Then save the code it returns (403, 404, etc)

If I'm understanding you correctly open a terminap and type

PHP Code

<?php 
nc 
-v targetip > codereturns.txt 

Then

PHP Code

<?php 
GET 
/ HTTP / 1.1
Host
: target ip 

I think this is what you want? IF it's not I apologize and I'll reform my answer.


* - Egregious Jr. - Nov 6, 2016

(Nov 6, 2016 02:17 PM)cudacore Wrote:  If I'm understanding you correctly open a terminap and type

PHP Code

<?php 
nc 
-v targetip > codereturns.txt 

Then

PHP Code

<?php 
GET 
/ HTTP / 1.1
Host
: target ip 

I think this is what you want? IF it's not I apologize and I'll reform my answer.
Uhm, this is the vb.net section, I'm looking for how to do this in vb.net.


* - Papa Cuda - Nov 6, 2016

(Nov 6, 2016 02:20 PM)Zach Wrote:  Uhm, this is the vb.net section, I'm looking for how to do this in vb.net.

🤣 oh my god I'm sorry I wasted your time.

This may actually help

PHP Code

<?php 
Imports System
.Threading
Imports System
.Net
Imports System
.Net.Sockets
Imports System
.Text
Imports System
.IO

Module Module1
    
Public ScanningThreads As Integer
    Sub Main
()
  
Console.WriteLine("Enter number of threads and press ENTER (50 is a good choice)")
  
ScanningThreads = Convert.ToInt32(Console.ReadLine())
  
FillPortsList()
  Try
    For 
i As Integer = 0 To ScanningThreads
    Dim GrabberThread 
As New Thread(AddressOf GrabBannerJob)
    
GrabberThread.Start()
    
Next i
  
Catch ex As Exception
    Console
.WriteLine(ex.ToString())
    
Console.ReadLine()
  
End Try
    
End Sub

    
Public _rng As New Random()

    Public Function 
rNext(ByVal min As Integer, ByVal max As Integer) As Integer
  
Return _rng.Next(min, max)
    
End Function

    Public Function 
GenerateIp() As String
  
Return rNext(11, 239) & "." & rNext(1, 255) & "." & rNext(1, 255) & "." & rNext(1, 255)
    
End Function

    Public 
PortsList As New List(Of Integer)()

    Public 
Sub FillPortsList()
  
PortsList.Add(21)
  
PortsList.Add(22)
  
PortsList.Add(1406)
  
PortsList.Add(25)
  
PortsList.Add(5900)
    
End Sub

    
Public Sub SockConnect(ByVal sIpadress As String, ByVal sPort As Integer)
  
Dim data As Byte() = New Byte(1023) {}
  
Dim stringData As String
  Dim recv 
As Integer
  Dim ipep 
As New IPEndPoint(IPAddress.Parse(sIpadress), sPort)
  
Dim server As New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
  Try
    
server.Connect(ipep)
    
Dim ns As New NetworkStream(server)
    If 
ns.CanRead Then
    recv 
= ns.Read(data, 0, data.Length)
    
stringData = Encoding.ASCII.GetString(data, 0, recv)
    If 
stringData <> "" Then
    Console
.WriteLine(sIpadress & ":" & sPort & " : " & stringData)
    
File.AppendAllText("banners.txt", sIpadress & ":" & sPort & " : " & stringData & vbCr & vbLf)
    
End If
    Else
    
ns.Close()
    
server.Close()
    
End If
  Catch
  
End Try

    
End Sub

    
Public Sub GrabBannerJob()
  While 
True
    
Try
    
Dim ipadress As String = GenerateIp()
    For 
Each lPort As Integer In PortsList
    Dim port 
As Integer = lPort
    SockConnect
(ipadress, port)
    
Next
                
Catch
                
End Try
            
End While
        
End Sub
End Module 



* - Egregious Jr. - Nov 6, 2016

(Nov 6, 2016 02:23 PM)cudacore Wrote:  🤣 oh my god I'm sorry I wasted your time.

This may actually help

PHP Code

<?php 
Imports System
.Threading
Imports System
.Net
Imports System
.Net.Sockets
Imports System
.Text
Imports System
.IO

Module Module1
    
Public ScanningThreads As Integer
    Sub Main
()
  
Console.WriteLine("Enter number of threads and press ENTER (50 is a good choice)")
  
ScanningThreads = Convert.ToInt32(Console.ReadLine())
  
FillPortsList()
  Try
    For 
i As Integer = 0 To ScanningThreads
    Dim GrabberThread 
As New Thread(AddressOf GrabBannerJob)
    
GrabberThread.Start()
    
Next i
  
Catch ex As Exception
    Console
.WriteLine(ex.ToString())
    
Console.ReadLine()
  
End Try
    
End Sub

    
Public _rng As New Random()

    Public Function 
rNext(ByVal min As Integer, ByVal max As Integer) As Integer
  
Return _rng.Next(min, max)
    
End Function

    Public Function 
GenerateIp() As String
  
Return rNext(11, 239) & "." & rNext(1, 255) & "." & rNext(1, 255) & "." & rNext(1, 255)
    
End Function

    Public 
PortsList As New List(Of Integer)()

    Public 
Sub FillPortsList()
  
PortsList.Add(21)
  
PortsList.Add(22)
  
PortsList.Add(1406)
  
PortsList.Add(25)
  
PortsList.Add(5900)
    
End Sub

    
Public Sub SockConnect(ByVal sIpadress As String, ByVal sPort As Integer)
  
Dim data As Byte() = New Byte(1023) {}
  
Dim stringData As String
  Dim recv 
As Integer
  Dim ipep 
As New IPEndPoint(IPAddress.Parse(sIpadress), sPort)
  
Dim server As New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
  Try
    
server.Connect(ipep)
    
Dim ns As New NetworkStream(server)
    If 
ns.CanRead Then
    recv 
= ns.Read(data, 0, data.Length)
    
stringData = Encoding.ASCII.GetString(data, 0, recv)
    If 
stringData <> "" Then
    Console
.WriteLine(sIpadress & ":" & sPort & " : " & stringData)
    
File.AppendAllText("banners.txt", sIpadress & ":" & sPort & " : " & stringData & vbCr & vbLf)
    
End If
    Else
    
ns.Close()
    
server.Close()
    
End If
  Catch
  
End Try

    
End Sub

    
Public Sub GrabBannerJob()
  While 
True
    
Try
    
Dim ipadress As String = GenerateIp()
    For 
Each lPort As Integer In PortsList
    Dim port 
As Integer = lPort
    SockConnect
(ipadress, port)
    
Next
                
Catch
                
End Try
            
End While
        
End Sub
End Module 
Don't think that's it. No problem lol


* - +Haze - Nov 6, 2016

(Nov 6, 2016 02:13 PM)cudacore Wrote:  Are you talking about banner grabbing, like with net cat or telnet?


(Nov 6, 2016 02:17 PM)cudacore Wrote:  If I'm understanding you correctly open a terminap and type

PHP Code

<?php 
nc 
-v targetip > codereturns.txt 

Then

PHP Code

<?php 
GET 
/ HTTP / 1.1
Host
: target ip 

I think this is what you want? IF it's not I apologize and I'll reform my answer.


(Nov 6, 2016 02:23 PM)cudacore Wrote:  🤣 oh my god I'm sorry I wasted your time.

This may actually help

PHP Code

<?php 
Imports System
.Threading
Imports System
.Net
Imports System
.Net.Sockets
Imports System
.Text
Imports System
.IO

Module Module1
    
Public ScanningThreads As Integer
    Sub Main
()
  
Console.WriteLine("Enter number of threads and press ENTER (50 is a good choice)")
  
ScanningThreads = Convert.ToInt32(Console.ReadLine())
  
FillPortsList()
  Try
    For 
i As Integer = 0 To ScanningThreads
    Dim GrabberThread 
As New Thread(AddressOf GrabBannerJob)
    
GrabberThread.Start()
    
Next i
  
Catch ex As Exception
    Console
.WriteLine(ex.ToString())
    
Console.ReadLine()
  
End Try
    
End Sub

    
Public _rng As New Random()

    Public Function 
rNext(ByVal min As Integer, ByVal max As Integer) As Integer
  
Return _rng.Next(min, max)
    
End Function

    Public Function 
GenerateIp() As String
  
Return rNext(11, 239) & "." & rNext(1, 255) & "." & rNext(1, 255) & "." & rNext(1, 255)
    
End Function

    Public 
PortsList As New List(Of Integer)()

    Public 
Sub FillPortsList()
  
PortsList.Add(21)
  
PortsList.Add(22)
  
PortsList.Add(1406)
  
PortsList.Add(25)
  
PortsList.Add(5900)
    
End Sub

    
Public Sub SockConnect(ByVal sIpadress As String, ByVal sPort As Integer)
  
Dim data As Byte() = New Byte(1023) {}
  
Dim stringData As String
  Dim recv 
As Integer
  Dim ipep 
As New IPEndPoint(IPAddress.Parse(sIpadress), sPort)
  
Dim server As New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
  Try
    
server.Connect(ipep)
    
Dim ns As New NetworkStream(server)
    If 
ns.CanRead Then
    recv 
= ns.Read(data, 0, data.Length)
    
stringData = Encoding.ASCII.GetString(data, 0, recv)
    If 
stringData <> "" Then
    Console
.WriteLine(sIpadress & ":" & sPort & " : " & stringData)
    
File.AppendAllText("banners.txt", sIpadress & ":" & sPort & " : " & stringData & vbCr & vbLf)
    
End If
    Else
    
ns.Close()
    
server.Close()
    
End If
  Catch
  
End Try

    
End Sub

    
Public Sub GrabBannerJob()
  While 
True
    
Try
    
Dim ipadress As String = GenerateIp()
    For 
Each lPort As Integer In PortsList
    Dim port 
As Integer = lPort
    SockConnect
(ipadress, port)
    
Next
                
Catch
                
End Try
            
End While
        
End Sub
End Module 

You deserve a -3 for shit posting, please stay out of this forum if you have no clue what you're talking about. I get the feeling you're trolling too.




@Op What library are you using to create the Http connection? WebClient, HttpWebRequest or HttpClient?


* - Egregious Jr. - Nov 6, 2016

(Nov 6, 2016 04:20 PM)+Haze Wrote:  You deserve a -3 for shit posting, please stay out of this forum if you have no clue what you're talking about. I get the feeling you're trolling too.




@Op What library are you using to create the Http connection? WebClient, HttpWebRequest or HttpClient?
I believe HttpWebRequest.


* - Diaxin - Nov 6, 2016

I have 0 knowledge of vb.net but google is a very powerful tool

http://stackoverflow.com/questions/692342/net-httpwebrequest-getresponse-raises-exception-when-http-status-code-400-ba

Looks like you need to catch an exception from WebException then just
HttpWebResponse httpResponse = (HttpWebResponse) response;
httpResponse.StatusCode <- will be your HTTP response code

Hope I was of at least some assistance.


* - Egregious Jr. - Nov 6, 2016

(Nov 6, 2016 04:29 PM)Diaxin Wrote:  I have 0 knowledge of vb.net but google is a very powerful tool

http://stackoverflow.com/questions/692342/net-httpwebrequest-getresponse-raises-exception-when-http-status-code-400-ba

Looks like you need to catch an exception from WebException then just
HttpWebResponse httpResponse = (HttpWebResponse) response;
httpResponse.StatusCode <- will be your HTTP response code

Hope I was of at least some assistance.
Thanks. I'll look into that.


* - mrkoolaid - Nov 6, 2016

isnt it just...

https://msdn.microsoft.com/en-us/library/system.net.httpstatuscode(v=vs.110).aspx


* - Decim - Nov 7, 2016

(Nov 6, 2016 02:07 PM)Zach Wrote:  How can I make GET request to the API and then save the HTTP status code?

The HttpWebResponse has a property called StatusCode.


* - Egregious Jr. - Nov 7, 2016

Thanks guys, I will take a look at those.


* - Ninja - Nov 7, 2016

https://gist.github.com/GekkeVent/cfd4566e76a7d1c150c66bf3e64ed8ca
This might help on your WebRequest journey.