elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Los 10 CVE más críticos (peligrosos) de 2020


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP) (Moderador: kub0x)
| | | |-+  System.Net.WebClient().DownloadString lee el código de forma errónea
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: System.Net.WebClient().DownloadString lee el código de forma errónea  (Leído 3,744 veces)
z3nth10n


Desconectado Desconectado

Mensajes: 1.583


"Jack of all trades, master of none." - Zenthion


Ver Perfil WWW
System.Net.WebClient().DownloadString lee el código de forma errónea
« en: 19 Octubre 2013, 22:04 pm »

Hola buenas, pues sí, parece ser o que bien la web de la que me estoy descargando el contenido tiene alguna forma de protección de la que desconozco...

O bien, que VB.NET no descarga correctamente el contenido de dicha página...

Estaba haciendo un descargador de música, mrtzcmp3.net

Código
  1. ReadOnly motor As String = "http://mrtzcmp3.net/"
  2.    Dim sourceString As String
  3.    Dim matches As MatchCollection
  4.    ReadOnly regexSearch As String = "D\?.+? _"
  5.    Dim firstMatch As String
  6.  
  7. Private Sub Buscar()
  8.  
  9.        sourceString = New System.Net.WebClient().DownloadString(motor & TextBox1.Text & "_1s.html")
  10.        matches = Regex.Matches(sourceString, regexSearch)
  11.        firstMatch = matches.Item(0).Value
  12.        firstMatch = Regex.Replace(firstMatch, "._$", "")
  13.  
  14.        TextBox1.Text = motor & firstMatch
  15.  
  16.        'sourceString = New System.Net.WebClient().DownloadString(motor & firstMatch)
  17.  
  18.        'File.AppendAllText(".\prueba.txt", sourceString)
  19.  
  20.    End Sub

El caso es que he hecho un TextBox que cuando introduzcas x palabra te la busque con esta web:

Código
  1. sourceString = New System.Net.WebClient().DownloadString(motor & TextBox1.Text & "_1s.html")

Le he hecho una especie de debug, File.AppendAllText(".\prueba.txt", sourceString)

he visto que era correcto he continuado y he hecho este Regex:

D\?.+? _

del cual, ahora me arrepiento, porque se ve que al descargar el source code, por ejemplo:

Código
  1. <a rel="nofollow" href="D?QAk1Bl0_Pitbull_Prueba _WRFDqkYz" target="_blank"><img alt="Download" title="Download" border="0" width="18" height="18" src="images/Download.png"></a>

La web bloquea la parte del link, y quita el "WRFDqkYz", para que no se pueda descargar...

Así que, supongo que la web está protegiendo ese contenido, para que nadie se lo pueda descargar, ahora la pregunta, porque cuando me meto desde Google Chrome si veo ese "enlace oculto" y cuando me lo descargo por VB.NET no me sale?

Que debería hacer para que saliese?

PD: A lo mejor, la chapucería me ayudaría en este caso, por ejemplo un webBrowser oculto, del que hiciese un webbrowser1.document.body.innerhtml o algo por el estilo...

Un saludo.

PD: Según se puede ver aquí también sucede: http://www.iwebtool.com/code_viewer?domain=mrtzcmp3.net%2Fprueba_1s.html Por lo que se ve que a web tiene algún tipo de protección...

PD: Es más, cuando hago click con un WebBrowser me salta todo el rato el mismo error:



« Última modificación: 19 Octubre 2013, 22:47 pm por Ikillnukes » En línea


Interesados hablad por Discord.
Shout

Desconectado Desconectado

Mensajes: 191


Acid


Ver Perfil
Re: System.Net.WebClient().DownloadString lee el código de forma errónea
« Respuesta #1 en: 19 Octubre 2013, 22:49 pm »

Cambia el user agent


En línea

I'll bring you death and pestilence, I'll bring you down on my own
z3nth10n


Desconectado Desconectado

Mensajes: 1.583


"Jack of all trades, master of none." - Zenthion


Ver Perfil WWW
Re: System.Net.WebClient().DownloadString lee el código de forma errónea
« Respuesta #2 en: 22 Octubre 2013, 16:10 pm »

Hola @shout, pues casi, pero no, resulta ser que son las cookies, cosa en la que no había caído y gracias a Kub0x pues me he dado cuenta..

Me dio algunos pasos a seguir, pero tiré por libre he hice este code, que por ahora parece que funciona a la perfección:

Código
  1.    ReadOnly motor As String = "http://mrtzcmp3.net/"
  2.    Dim sourceString As String
  3.    Dim matches As MatchCollection
  4.    ReadOnly regexSearch As String = "D\?.+? _"
  5.    Dim firstMatch As String
  6.    Dim pageHtml As String
  7.    Dim url As String
  8.    Dim Cookies As New CookieContainer
  9.    Dim cookieString As String
  10.    Dim request As System.Net.HttpWebRequest
  11.    Dim response As System.Net.HttpWebResponse
  12.    Dim cookieName As String
  13.    Dim sr As System.IO.StreamReader
  14.  
  15.  
  16.    Private Sub Buscar()
  17.  
  18.        'Cookie Name
  19.        cookieName = "haras"
  20.  
  21.        'Get first source
  22.        request = CType(HttpWebRequest.Create(motor & TextBox1.Text & "_1s.html"), HttpWebRequest)
  23.        request.CookieContainer = Cookies 'Request Cookies
  24.        response = CType(request.GetResponse(), HttpWebResponse)
  25.  
  26.        'DO multiple things with the cookies
  27.        For Each cookieValue As Cookie In response.Cookies
  28.            If cookieValue.ToString.Substring(0, cookieValue.ToString.IndexOf("=")) = cookieName Then
  29.                cookieString = cookieValue.ToString.Replace(cookieName & "=", "") 'Get haras cookie value
  30.            End If
  31.            Cookies.Add(cookieValue) 'Add cookies to the container for use it again
  32.        Next
  33.  
  34.        'Read Source String
  35.        sr = New System.IO.StreamReader(response.GetResponseStream())
  36.        sourceString = sr.ReadToEnd()
  37.  
  38.        'Check the result
  39.        matches = Regex.Matches(sourceString, regexSearch)
  40.  
  41.        'If results = 0 stop sub
  42.        If matches.Count = 0 Then
  43.            MsgBox("Se encontraron 0 resultados de esta canción.", MsgBoxStyle.Information, "Información")
  44.            Exit Sub
  45.        End If
  46.  
  47.        'Get first song link
  48.        firstMatch = matches.Item(0).Value
  49.  
  50.        'Enter with Fake Cookie
  51.        request = CType(HttpWebRequest.Create(motor & firstMatch & cookieString), HttpWebRequest)
  52.        request.CookieContainer = Cookies
  53.        response = CType(request.GetResponse(), HttpWebResponse)
  54.  
  55.        'Read source String
  56.        sr = New System.IO.StreamReader(response.GetResponseStream())
  57.        sourceString = sr.ReadToEnd()
  58.  
  59.        'Append text to a new text file (this will be the future step, for get song download link)
  60.        If Not File.Exists(".\prueba.html") Then
  61.            File.AppendAllText(".\prueba.html", sourceString)
  62.        Else
  63.            File.Delete(".\prueba.html")
  64.            File.AppendAllText(".\prueba.html", sourceString)
  65.        End If
  66.  
  67.        'For advise that the function has finished
  68.        MsgBox("Done!")
  69.  
  70.    End Sub

Parte de esta información la he sacado de un snippet que me ha servido bastante para hacer lo que yo quería:

Código
  1.    Private Sub Login_in_FB()
  2.        Dim cookieJar As New Net.CookieContainer()
  3.        Dim request As Net.HttpWebRequest
  4.        Dim response As Net.HttpWebResponse
  5.        Dim strURL As String = ""
  6.  
  7.        Try
  8.            'Get Cookies
  9.            strURL = "https://login.facebook.com/login.php"
  10.            request = CType(HttpWebRequest.Create(strURL), HttpWebRequest)
  11.            request.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3"
  12.            request.Method = "GET"
  13.            request.CookieContainer = cookieJar
  14.            response = CType(request.GetResponse(), HttpWebResponse)
  15.  
  16.            For Each tempCookie As Net.Cookie In response.Cookies
  17.                cookieJar.Add(tempCookie)
  18.            Next
  19.  
  20.            'Send the post data now
  21.            request = CType(HttpWebRequest.Create(strURL), HttpWebRequest)
  22.            request.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3"
  23.            request.Method = "POST"
  24.            request.AllowAutoRedirect = True
  25.            request.CookieContainer = cookieJar
  26.  
  27.            Dim writer As StreamWriter = New StreamWriter(request.GetRequestStream())
  28.            writer.Write("email=username&pass=password")
  29.            writer.Close()
  30.            response = CType(request.GetResponse(), HttpWebResponse)
  31.  
  32.            'Get the data from the page
  33.            Dim stream As StreamReader = New StreamReader(response.GetResponseStream())
  34.            Dim data As String = stream.ReadToEnd()
  35.            response.Close()
  36.  
  37.            If data.Contains("<title>Facebook") = True Then
  38.                'LOGGED IN SUCCESSFULLY
  39.                MessageBox.Show("logged in sucessfully")
  40.            Else
  41.                MessageBox.Show("Not logged in")
  42.            End If
  43.  
  44.        Catch ex As Exception
  45.            MessageBox.Show(ex.ToString)
  46.        End Try
  47.    End Sub

Un saludo.
En línea


Interesados hablad por Discord.
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Alguna forma de optimizar el codigo?
Programación Visual Basic
demoniox12 8 2,653 Último mensaje 6 Febrero 2008, 18:53 pm
por demoniox12
AYUDA CON WEBCLIENT DE VB NET
.NET (C#, VB.NET, ASP)
70N1 6 6,282 Último mensaje 25 Noviembre 2008, 16:14 pm
por MANULOMM
Función System() exec() passthru() Buscando codigo
PHP
Dem0ny 4 3,090 Último mensaje 4 Enero 2010, 22:58 pm
por Dem0ny
Ayuda con WebClient
.NET (C#, VB.NET, ASP)
Andre20 1 1,798 Último mensaje 22 Febrero 2013, 13:24 pm
por Novlucker
Grave error de MediaMarkt vendiendo móviles a precio de derribo de forma errónea
Noticias
wolfbcn 2 1,654 Último mensaje 8 Enero 2018, 10:36 am
por Orubatosu
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines