Thursday, February 5, 2015

用Fiddler捕捉phone的traffic

具体细节参看官网:http://docs.telerik.com/fiddler/Configure-Fiddler/Tasks/ConfigureForiOS
1. phone & 电脑连接同一个wifi
2. 获取电脑的IP地址, 并且输入到phone的wifi设置中,port 8888是fiddler默认的。

























3. 在Fiddler中设置options->connections->Allow remote computers to connect以及安装Certificate Maker plugin。
4. 在Fiddler中设置options->HTTPS->Actions->Trust root certificate
5. iphone6以上还需要信任证书Settings -> General -> About -> Certificate Trust Settings。登录手机 浏览器,输入地址192.168.1.3:8888。如果看见Fiddler Echo Service说明成功。

6. 可选项:fiddler中设置或者HTTPS
此时我们可以见到fiddler开始捕捉手机上的traffic,当然电脑上的traffic也会捕捉,process可以区分出他们,chrome是来自电脑,空白的是来自phone















7. 如上图所示,有的traffic会显示tunnel to,表示这些request用了SSL,我们在手机安装一些证书来骗过这些网站从而获得细节
电脑中fiddler的网址是http://localhost:8888/     证书也位于这里
在手机我们输入电脑的IP,port是8888,就可以访问该网址,如上述例子,我们在手机浏览器输入http://192.168.1.3:8888/  我们见到一个hyperlink: you can download the Fiddler certificate
安装了之后,就可以看到这些traffic了,不过不是所有SSL都可以骗,比如twitter就不可以了。
要删除fiddler cert可以settting->general->profile(iphone)

重新安装Fiddler的话都要重新再手机上安装此证书,在iphone中,证书通过以上方法可能打开不了,可以在fiddler把证书下载下来Options->HTTPS->Actions->Export root cert to desktop然后通过邮件发到手机即可打开。

























Android的配置:
http://docs.telerik.com/fiddler/Configure-Fiddler/Tasks/ConfigureForAndroid

另一个Post

Monday, February 2, 2015

Selenium in C# - Browser Automation

OpenQA.Selenium:
Start: http://docs.seleniumhq.org/docs/03_webdriver.jsp
SetPreference: http://seleniumeasy.com/selenium-tutorials/firefox-profile-preferences-using-selenium-webdriver

FindElement(By): http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/By.html?_sm_au_=iVVsMF35HZfF7QWj

FirefoxProfile profile = new FirefoxProfile();
profile.SetPreference("network.proxy.http", "1234");
FirefoxDriver browser = new FirefoxDriver(profile);
browser.PageSource.Contains("abcd");
IWebElement total = browser.FindElement(By.ClassName("ddd"));//css class
String totalStr = total.Text;

ReadOnlyCollection<IWebElement> children = total.FindElements(By.ClassName("eee")).FindElement(By.ClassName("fff"));
foreach (IWebElement product in children){}
String innerHtml = total.GetAttribute("innerHTML");
total.Click();

//selelium's approach: scroll an element into view
browser.ExecuteJavaScript("arguments[0].scrollIntoView(true);", total);

xpath
("//div[@class='abc']")[1]
("//div[contains(@class, 'abc']")//h4[contains(text(), 'bb')]


KB: C#

AppSettingsReader:
Read app.config file

XmlDocument & XmlNode (Read XML file):
XmlDocument configDoc = new XmlDocument();
configDoc.Load(fileName);
XmlNode oneNode = configDoc.SelectSingleNode("//config/");
String abc = botNode.Attributes["proxy"];

Attribute & CustomAttributeData:
FieldInfo[] fs = obj.GetType().GetFields();
foreach (FieldInfo f in fs)
{
IList<CustomAttributeData> attributes = CustomAttributeData.GetCustomAttributes(f);
        foreach (CustomAttributeData attribute in attributes)
        {
             //check if the field was marked as [ConfigValue]
             if (attribute.Constructor.DeclaringType.Equals(typeof(ConfigValue)))
    {}
}
}



    [AttributeUsage(AttributeTargets.Field)]
    public class ConfigValue : Attribute
    {
        private String prameName;
        public ConfigValue(String name)
        {
            prameName = name;
        }

    }

    [AttributeUsage(AttributeTargets.Field)]
    public class RegexFile : Attribute
    {
        private String fileName;
        public RegexFile(String name)
        {
            fileName = name;
        }
    }


Use:
        [ConfigValue]
        String proxy;

        [RegexFile("rabc.regex")]
        private Regex rabc;