Jump to content

VB6 > AutoIt: Any ideas why this isnt working?


AzKay
 Share

Recommended Posts

Option Explicit

Private Const FILTER_PROTO_ICMP = 1
Private Const FILTER_PROTO_TCP = 6
Private Const FILTER_PROTO_UDP = 11
Private Const FILTER_TCPUDP_PORT_ANY = 0
Private Const FILTER_ICMP_TYPE_ANY = 255
Private Const FILTER_ICMP_CODE_ANY = 255

Private Const FD_FLAGS_NOSYN = 1

Private Enum ENUM_PFADDRESSTYPE
    PF_IPV4 = 0
    PF_IPV6 = 1
End Enum

Private Enum ENUM_PF_ACTION
    PF_ACTION_FORWARD = 0
    PF_ACTION_DROP = 1
End Enum

Private Type PPF_FILTER_DESCRIPTOR
    dwFilterFlags As Long
    dwRule As Long
    pfatType As ENUM_PFADDRESSTYPE
    SrcAddr As Long
    SrcMask As Long
    DstAddr As Long
    DstMask As Long
    dwProtocol As Long
    fLateBound As Long
    wSrcPort As Integer
    wDstPort As Integer
    wSrcPortHighRange As Integer
    wDstPortHighRange As Integer
End Type

Private Declare Function PfCreateInterface Lib "Iphlpapi.dll" Alias "_PfCreateInterface@24" (dwName As Long, inAction As ENUM_PF_ACTION, outAction As ENUM_PF_ACTION, bUseLog As Boolean, bMustBeUnique As Boolean, ppInterface As Long) As Long
Private Declare Function PfBindInterfaceToIPAddress Lib "Iphlpapi.dll" Alias "_PfBindInterfaceToIPAddress@12" (ByVal pInterface As Long, PFADDRESSTYPE As ENUM_PFADDRESSTYPE, IPAddress As Any) As Long
Private Declare Function PfAddFiltersToInterface Lib "Iphlpapi.dll" Alias "_PfAddFiltersToInterface@24" (ByVal ih As Long, ByVal cInFilters As Long, ByRef pfiltIn As Any, ByVal cOutFilters As Long, ByRef pFiltOut As Any, ByRef pfHandle As Long) As Long
Private Declare Function PfDeleteInterface Lib "Iphlpapi.dll" Alias "_PfDeleteInterface@4" (ByVal ppInterface As Long) As Long
Private Declare Function PfUnBindInterface Lib "Iphlpapi.dll" Alias "_PfUnBindInterface@4" (ByVal ppInterface As Long) As Long
Private Declare Function PfRemoveFilterHandles Lib "Iphlpapi.dll" Alias "_PfRemoveFiltersFromInterface@20" (ByVal ih As Long, ByVal cInFilters As Long, ByRef pfiltIn As Any, ByVal cOutFilters As Long, ByRef pFiltOut As Any) As Long

Dim hInterface As Long
Dim InFilter As PPF_FILTER_DESCRIPTOR
Dim IP(3) As Byte

Public Sub BlockInternet()

'// Create interface
'// Drop or Forward
PfCreateInterface 0&, PF_ACTION_FORWARD, _
PF_ACTION_FORWARD, False, True, hInterface

'// Local IP in bytes ( Must be changed to your local IP address )
'// ex: 192.168. etc..
IP(0) = 127
IP(1) = 0
IP(2) = 0
IP(3) = 1

'// Bind interface with local ip
PfBindInterfaceToIPAddress hInterface, _
ByVal PF_IPV4, IP(0) '// local ip



'// Build structure
InFilter.dwFilterFlags = FD_FLAGS_NOSYN              '//always this value
InFilter.dwRule = 0                                  '//always this value
InFilter.pfatType = PF_IPV4                          '//using ipV4 addresses
InFilter.SrcAddr = IP(0)                                '//set local ip
InFilter.SrcMask = 0                                    '//mask for local ip
InFilter.wSrcPort = 80                                '//any source port
InFilter.wSrcPortHighRange = 0
InFilter.DstAddr = 0                                    '//any destination
InFilter.DstMask = 0
InFilter.wDstPort = 80                                '//destination port 80(http service)
InFilter.wDstPortHighRange = 80
InFilter.dwProtocol = FILTER_PROTO_TCP                '// Tcp protocol(6)


'// Add interface to filters
PfAddFiltersToInterface hInterface, 0, _
InFilter, 0, Null, hInterface                          'No outfilter can be passed as NULL MSDN

MsgBox "Click OK to terminate Interface"

PfRemoveFilterHandles hInterface, 1, InFilter, 0, Null  '// Remove
PfUnBindInterface hInterface                            '// Un-Bind
PfDeleteInterface hInterface                            '// Delete

End Sub

^ Blocks all the activity on port 80 until you close the messagebox

Dim $hInterface;, $ip[4] = [192, 168, 0, 5]

$ret = PfCreateInterface(0, 0, 0, 0, 1, $hInterface)
$ret = PfBindInterfaceToIPAddress($hInterface, 0, @IPAddress1) ;$ip

$InFilter = DllStructCreate("long dwFilterFlags;" & _
                            "long dwRule;" & _
                            "long pfatType;" & _
                            "long SrcAddr;" & _
                            "long SrcMask;" & _
                            "long DstAddr;" & _
                            "long DstMask;" & _
                            "long dwProtocol;" & _
                            "long fLateBound;" & _
                            "int wSrcPort;" & _
                            "int wDstPort;" & _
                            "int wSrcPortHighRange;" & _
                            "int wDstPortHighRange")

DllStructSetData($InFilter, "dwFilterFlags", "")
DllStructSetData($InFilter, "dwRule", "0")
DllStructSetData($InFilter, "pfatType", "0")
DllStructSetData($InFilter, "SrcAddr", @IPAddress1) ;$ip
DllStructSetData($InFilter, "SrcMask", "0")
DllStructSetData($InFilter, "wSrcPort", "80")
DllStructSetData($InFilter, "wSrcPortHighRange", "0")
DllStructSetData($InFilter, "DstAddr", "0")
DllStructSetData($InFilter, "DstMask", "0")
DllStructSetData($InFilter, "wDstPort", "80")
DllStructSetData($InFilter, "wDstPortHighRange", "80")
DllStructSetData($InFilter, "dwProtocol", "6")

$ret = PfAddFiltersToInterface($hInterface, 0, $InFilter, 0, "", $hInterface)

MsgBox(0, "", "")

$ret = PfRemoveFilterHandles($hInterface, 1, $InFilter, 0, "")
$ret = PfUnBindInterface($hInterface)
$ret = PfDeleteInterface($hInterface)

Func PfCreateInterface($dwName, $inAction, $outAction, $bUseLog, $bMustBeUnique, $ppInterface)
    $ret = DllCall("Iphlpapi.dll", "long", "_PfCreateInterface@24", "long", $dwName, "int", $inAction, "int", $outAction, "int", $bUseLog, "int", $bMustBeUnique, "long", $ppInterface)
    return $ret[0]
EndFunc

Func PfBindInterfaceToIPAddress($pInterface, $PFADDRESSTYPE, $IPAddress)
    $ret = DllCall("Iphlpapi.dll", "long", "_PfBindInterfaceToIPAddress@12", "long", $pInterface, "int", $PFADDRESSTYPE, "str", $IPAddress)
    return $ret[0]
EndFunc

Func PfAddFiltersToInterface($ih, $cInFilters, $pfiltIn, $cOutFilters, $pFileOut, $pfHandle)
    $ret = DllCall("Iphlpapi.dll", "long", "_PfAddFiltersToInterface@24", "long", $ih, "long", $cInFilters, "str", $pfiltIn, "long", $cOutFilters, "str", $pFileOut, "long", $pfHandle)
    return $ret[0]
EndFunc

Func PfDeleteInterface($ppInterface)
    $ret = DllCall("Iphlpapi.dll", "long", "_PfDeleteInterface@4", "long", $ppInterface)
    return $ret[0]
EndFunc

Func PfUnBindInterface($ppInterface)
    $ret = DllCall("Iphlpapi.dll", "long", "_PfUnBindInterface@4", "long", $ppInterface)
    return $ret[0]
EndFunc

Func PfRemoveFilterHandles($ih, $cInFilters, $pfiltIn, $cOutFilters, $pFileOut)
    $ret = DllCall("Iphlpapi.dll", "long", "_PfRemoveFiltersFromInterface@20", "long", $ih, "long", $cInFilters, "str", $pfiltIn, "long", $cOutFilters, "str", $pFileOut)
    return $ret[0]
EndFunc

^ This doesnt error out; The dllcalls return 0. So I dont know what the problem is.

Though, this is the first time ive used the DllStructCreate; So that might be a problem.

Any ideas?

# MY LOVE FOR YOU... IS LIKE A TRUCK- #
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...