title: authentication

date: 2016-01-13 14:33:22

categories: information-security

tags: authentication

  • Exercise1
  • There are many bugs and vulnerabilities in the current utility for transferring money.

    Find as many bugs as you can. For now, just focus on bugs that an adversary can trigger

    by giving unanticipated values to the transfer page.

    Think carefully about what kinds of inputs an attacker might provide,

    and try them out by entering them on the transfer page.

    Please write down detail descriptions of your observation in bugs.txt.

    (You should find at least 4 different bugs.)
     这个网站存在以下漏洞:
    (1)没有判断转账金额和自己余额的大小
    (2)没有判断转账金额是否为负数
    (3)没有判断被转入用户的余额上界
    (4)没有判断转出用户的余额下界
    (5)没有判断被转账用户是否存在

  • Exercise2
  • Fix as many bugs as you can
	在handle.c文件中的handlePostTransfer函数中
我们添加一条判断输入是否合法的语句
来控制是否修改数据库里面的金额。
if(money<0 || !Db_checkUser(to) || strcmp(from, to) == 0
||(money > fromBalace) || (toBalace + money <0))
{
handlePostLogin (fd, from, 0, 0);
return;
}
实验结果显示:能成功阻止E1中的漏洞。

  • Exercise3

  • Read the source code of the login web page (in your browser),and the server's source code.

    Make sure that you make it clear that how the server identify who is transferring.

     首先,一个新的用户登录
    server将会接收fd 发送给httpd进程
    然后httpd进程开始发分析客户请求
    GET请求将会发送给filesv进程
    POST请求将会发给banksv进程 在交易之前
    banksv进程处理request请求的body部分
    得到交易金额、人员等信息
    然后开始更新数据库 我们可以发送POST请求
    伪装request请求的body部分
    就可以达到偷偷转账的目的

  • Exercise4

  • Try to construct a POST request about the money transferring,

    which steal money from some account if you know the victim’s account.

    You can use browser.c or some tools, such as firebug to construct the request.

      Char *req="POST / HTTP/1.1\r\nHost: 127.0.0.1\r\n
    Content-Type:
    application/x-www-form-urlencoded\r\n
    Content-Length:
    72\r\n\r\n
    transfer_from=a&transfer_to=b&transfer_money=20&submit_transfer=Transfer\r\n";

  • Exercise5
	用户登录时候生成cookie,
用户操作账户金额时验证cookie的机制来保护信息不被恶意操作,
为了每次cookie的值都不是固定的,我们可以通过登录时间和用户名的组合产生cookie。
产生cookie之后,服务器发送cookie给浏览器,
进行转账交易之前,将post请求中的cookie与服务器中的cookie做比较,
相同则进行转账,不同则拒绝转账。
现在我们进行转账的时候,抓包工具就可以抓取到cookie字段了
其中:
服务器在用户登录时候产生cookie并发送至浏览器:
productCookie(name,logintime);
strcpy(cookieGet,cookie);
write(fd,cookieGet,strlen(cookieGet));
从浏览器中获取cookie:
Header_t head=tree->headers;
while(head)
{
if(strcmp(head->key,"Cookie:")==0)
strcat(cookieGet,head->value);
head=head->next;
}
验证请求:
if(validCookie(cookieGet,from))
{
handlePostLogin(fd,from,0,0);
return;
}
生成cookie函数:
char cookie[100]="Set-cookie:mycookie=";
static char cookieGet[100]="";
//product cookie
void productCookie(char *name,char *time)
{
int len=strlen(time);
char cookie1[100]="\0";
char cookie2[200]="\0";
strcat(cookie2,name);
strcat(cookie2,"#");
strncpy(cookie1,time,len-1);
strcat(cookie2,cookie1);
strcat(cookie,cookie2);
strcat(cookie,";path=/;domain=127.0.0.1\r\n\r\n");
}
验证cookie函数:
int validCookie(char *parameter,char *name)
{
char cookie1[100]="";
char cookie2[100]="";
int i=0;
int k=0;
int flag=0;
if(parameter[0]=='\0')
return 1;
for(;i<strlen(parameter);i++)
{
if(flag)
{
cookie1[k]=parameter[i];
k++;
}
if(parameter[i]=='=')
flag=1;
}
i=0;
while(cookie1[i]=='#'&&i<strlen(cookie1))
{
cookie2[i]=cookie1[i];
i++;
}
return strcmp(cookie2,name);
}

  • Exercise6
  • Using the Wireshark to steal the cookie,

    and then use the cookie to make fake POST request.

    Send the request to the server and transfer some one else's money.

    • 抓包偷cookie
     char *req="POST /index.html HTTP/1.1\r\n
    Host: 127.0.0.1\r\n
    User-Agent: Mozilla/5.0 Firefox/43.0\r\n
    Cookie: mycookie=a#Sun Dec 27 22:20:52 2015\r\n
    Connection: keep-alive\r\n
    Content-Type: application/x-www-form-urlencoded\r\n
    Content-Length: 72\r\n
    transfer_from=a&transfer_to=b&transfer_money=20&submit_transfer=Transfer\r\n";

  • Exercise7
  • Encrypt the cookie
     Cookie加密:我们的cookie是明文传输的,现在通过简单的加密函数,让其以密文的形式在网络中传输。
    生成cookie的时候加密:
    key(cookie2);
    验证cookie的时候解密:
    unkey(cookie1);
    void key(char *test)
    {
    int i;
    int count=strlen(test);
    for(i=0;i<count;i++)
    {
    test[i]=test[i]+i+5;
    if((int)test[i]>126)
    test[i]='~';
    }
    test[i]='\0';
    } void unkey(char *test)
    {
    int count=strlen(test);
    int i;
    for(i=0;i<count;i++)
    test[i]=test[i]-i-5;
    test[i]='\0';
    }

信息安全实验四:information-security的更多相关文章

  1. Oracle 实验四-七

    shutdown immediateORA-01097: 无法在事务处理过程中关闭 - 请首先提交或回退 解决:先 "commit" 实验四 SQL Production :: C ...

  2. 20145204&20145212信息安全系统实验四报告

    20145204信息安全设计基础实验四报告 博客链接:信息安全设计基础实验

  3. 科软-信息安全实验1-ICMP重定向

    目录 一 前言 二 Talk is cheap, show me the code 三 效果演示 四 遇到的问题&解决 一 前言 文章不讲解理论知识哈,想学习理论知识的,认真听课

  4. php实验四

    实验四 1.创建一个Person类,Person中包含三个属性name,age,wealth,分别设置为public,private,protected,再定义Person类的子类Student. 2 ...

  5. 实验四 简单的PV操作

    实验四 简单的PV操作 专业 网络工程   姓名 方俊晖 学号 201406114309 一.        实验目的 1.掌握临界区的概念及临界区的设计原则: 2.掌握信号量的概念.PV操作的含义以 ...

  6. Java实验四

    20145113 Java实验四 快捷键 之前没怎么记ISDEA的快捷键,但是熟练使用快捷键可以带来很多的便利,于是先开始学习一些常用的快捷键,就采用它默认的快捷键,这样后期就不会出现冲突,一些and ...

  7. 20145316&20145229实验四:驱动程序设计

    20145316&20145229实验四:驱动程序设计 结对伙伴:20145316 许心远 博客链接:http://www.cnblogs.com/xxy745214935/p/6130871 ...

  8. 20145301&20145321&20145335实验四

    20145301&20145321&20145335实验四 这次实验我的组员为:20145301赵嘉鑫.20145321曾子誉.20145335郝昊 实验内容详见:实验四

  9. 20145212 实验四《Andoid开发基础》

    20145212 实验四<Andoid开发基础> 实验内容 安装Android Studio 运行安卓AVD模拟器 使用Android运行出模拟手机并显示自己的学号 实验过程 一.安装An ...

随机推荐

  1. ACM中Java的应用

    先说一下Java对于ACM的一些优点吧: (1) 对于熟悉C/C++的程序员来说Java 并不难学,两周时间基本可以搞定一般的编程,再用些时间了解一下Java库就行了.Java的语法和C++非常类似, ...

  2. SQL 截图

  3. selenium webdriver python 开始

    学习资料: Selenium with Python: http://selenium-python.readthedocs.org/en/latest/index.html 乙醇的python se ...

  4. 给Eclipse提速的7个技巧(转载的)

      大约一个月前,我发表了一篇博客,其中介绍了对Eclipse的爱与恨. 有些人问我如何给Eclipse提速,这篇文章就来讨论这个问题.顺带提一下,这篇文章不是比较IDE,所以不要说你讨厌某个IDE而 ...

  5. Exception in thread "main" com.sun.xml.internal.ws.streaming.XMLStreamReaderException: unexpected XML tag.

    webservice 抛异常,原因: public class HeaderHandler implements SOAPHandler<SOAPMessageContext>{ @Ove ...

  6. Sublime Text3 配置markdown插件

    sublime是一个亮骚的文本编辑器,而且是跨三大平台,而markdown是一门标记语法,对于记录真是神器,具体语法百度很多,下面教你在sublime上配置markdown. 这两个神器结合起来简直好 ...

  7. JavaScript的闭包详解

    (1)定义: 函数内部返回一个函数,返回出来的这个函数叫做被我们称之为闭包(个人理解的最简单的表现形式,) (2)为什么要使用闭包呢? 局部变量在函数执行完之后就会被GC回收,有时候我们想在外部访问内 ...

  8. 2015 GOOGLE I/O大会看点总结:新的开发工具及云端测试工具

        http://ask.android-studio.org/?/article/48 尽管凌晨开始的主题演讲略显晦涩并继承了谷歌一贯的东一句西一句想起啥说啥的混乱风格,但期待用技术改变世界的技 ...

  9. android 仿EF看视频弹出练习功能

    第一次看到英孚iPad上的视频练习,感觉好有创意,让我们学习英语起来更加的有激情.而且不仅仅是在EF上有.相信在其它的学校肯定也会有的. 以上也我尝试把它写出来的原因了. 以下让我们来看看它的效果是怎 ...

  10. Scala学习笔记之:tuple、array、Map

    [TOC] 本文<快学Scala>的笔记 tuple学习笔记 tuple的定义 对偶是元组(tuple)的最简单形态--元组是不同类型的值的聚集. 元组的值是通过将单个值包含在圆括号中构成 ...