Server MAC address and obfuscation

2019-06-06 08:00发布

问题:

I am developing a VB.net windows forms application. My application connects to a name specified computer on network and gets its MAC address and performs a check, in order to prevent the use of the application "out-of-office".

The Mainpage load event is as follows:

Private Declare Function inet_addr Lib "wsock32.dll" (ByVal s As String) As Integer

Private Declare Function SendARP Lib "iphlpapi.dll" (ByVal DestIP As Integer, ByVal SrcIP As Integer, ByRef pMACAddr As Integer, ByRef PhyAddrLen As Integer) As Integer

Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByRef dst As Byte, ByRef src As Integer, ByVal bcount As Integer)

Private Sub Mainpage_Load(sender As Object, e As EventArgs) Handles MyBase.Load



    Dim ServerName = "Office-NAS"
    Dim IpCollection As New Collection
    Try
        Dim ipE As Net.IPHostEntry = System.Net.Dns.GetHostEntry(ServerName)
        Dim IpA() As Net.IPAddress = ipE.AddressList
        For i = 0 To IpA.GetUpperBound(0)
            IpCollection.Add(IpA(i).ToString)
        Next
    Catch

        MessageBox.Show("Not connected to server - exiting")
        Me.Close()

    End Try

    Dim sip As String = IpCollection(1)
    Dim inet As Integer
    Dim b(6) As Byte
    Dim pMACAddr As Integer
    Dim j As Short
    Dim sResult As String = ""


    inet = inet_addr(sip)
    If SendARP(inet, 0, pMACAddr, 6) = 0 Then
        CopyMemory(b(0), pMACAddr, 6)
        For j = 0 To 5
            sResult = sResult & Microsoft.VisualBasic.Right("0" & Hex(b(j)), 2)
            If j < 5 Then sResult &= "-"
        Next
    End If



    MessageBox.Show(sResult) '' The server's MAC address


    Dim MACToBeChecked As String = "00-11-32-2E-93-76"

    Stop
    If sResult <> MACToBeChecked Then
        MessageBox.Show("Not in office- Exiting")
        Me.Close()
    End If


'Some other stuff


End Sub

I did not write the getting the IP address and getting the MAC address parts, I found them online. They work just perfectly !

Now, I also want to use an obfuscator to make my code harder to decompile. I am using Eazfuscator.NET. It works fine, however when I use it, the above code does not work. I realized that when obfuscation is on, the Servers MAC address is not obtained correctly. Actuaally, the first 4 pairs of characters are correct, but the last 2 pairs are mistaken!! So I can not perfrom the check correctly.

I am very confused and stuck on this problem. I would be grateful for any kind of help.