首页 文章 精选 留言 我的

精选列表

搜索[操作审计],共10022篇文章
优秀的个人博客,低调大师

php代码审计分段学习(php_bug)[2]

参考:https://github.com/bowu678/php_bugs 11.sql闭合绕过 $sql = "select user from php where (user='$user') and (pw='$pass')";嗯好吧这个不就是sqli-labs的Less-3么,放下writeup好了http://localhost/php_bug/11.php/?user=admin')# 12.X-Forwarded-For绕过指定IP地址 if ($GetIPs=="1.1.1.1"){ echo "Great! Key is *********";},直接bp抓包,在http头里面加上X-Forwarded-For:1.1.1.1就行了,X-Forwarded-For代表客户端,里面存放的是HTTP端请求的真实ip。 13.md5加密相等绕过 $a != 'QNKCDZO' && $md51 == $md52,两个字符串不相等但是md5后的值相等,记下writeup。 var_dump(md5('240610708') == md5('QNKCDZO'));//ture var_dump(md5('aabg7XSs') == md5('aabC9RqS'));//ture var_dump(sha1('aaroZmOk') == sha1('aaK1STfY'));//ture var_dump(sha1('aaO8zKZF') == sha1('aa3OFF9m'));//ture var_dump('0010e2' == '1e3');//ture var_dump('0x1234Ab' == '1193131');//ture var_dump('0xABCdef' == ' 0xABCdef');//ture ==对比的时候会进行数据转换,0eXXXXXXXXX就成0了,如果比较一个数字和字符串或者比较涉及到数字内容的字符串,则字符串会被转换为数值并且比较按照数值来进行,嗯还是用===好一些,尽量不要用==。 14.intval函数四舍五入 emmmm,这个函数。。。先是查询的时候intval($_GET['id'])为1024,但是$_GET['id']又不能为1024,直接1024.325加个小数点就行了。。intval会自动将小数点后面的数值舍掉 15 strpos数组绕过NULL与ereg正则%00截断 @ereg ("^[1-9]+$", $_GET['nctf'] strpos ($_GET['nctf'], '#biubiubiu') ①.这个是要求输入的内容必须为纯数字,但是还有出现#biubiubiu的内容,eregde%00截断可以实现,但是题目上给的#需要url编码一下,要不实现不了。http://localhost/php_bug/15.php?nctf=12414%00%23biubiubiu ②.strpos()找的是字符串,那么传一个数组给它,strpos()出错返回null,null!==false,符合要求. 所以输入nctf[]= ,ereg()在出错时返回的也是null,null!==falsehttp://localhost/php_bug/15.php?nctf[]= 16.SQL注入or绕过 $query='SELECT * FROM interest WHERE uname=''.$username.'' AND pwd=''.$password.'';'; $query='SELECT * FROM users WHERE name=''admin'' AND pass=''or 1 #'';'; ?username=admin'' AND pass=''or 1 #&password= 有点传说中的花式闭合的感觉。。 17.密码md5比较绕过 总感觉眼熟,emmm和第九个是一样的。。。 ?user=' union select '202cb962ac59075b964b07152d234b70' #&pass=123 18.md5()函数===使用数组绕过 $_GET['username'] == $_GET['password'] md5($_GET['username']) === md5($_GET['password'])http://localhost/php_bug/18.php?username[]=1&password[]=2,前面已经在sha1()函数比较绕过这个里面详细说过了,,基本同样道理,这里就不多做描述了。 19 ereg()函数strpos() 函数用数组返回NULL绕过 ereg ("^[a-zA-Z0-9]+$", $_GET['password']) strpos ($_GET['password'], '--') emm这个和15是一样的只是ereg()的这个函数现在要求的是只能出现字母和数字,依旧是两种方法http://localhost/php_bug/19.php?password[]=http://localhost/php_bug/19.php?password=12a%00-- 十六进制与数字比较 ($digit >= $one) && ($digit <= $nine) $number == $temp 这个题的要求是输入的数字不能是1~9的数字,但是又要与3735929054相等,转化为16进制http://localhost/php_bug/20.php?password=0xdeadc0de 54975581388转换成16进制为ccccccccc

优秀的个人博客,低调大师

php代码审计分段学习(php_bug)[1]

参考:https://github.com/bowu678/php_bugs 1.extract变量覆盖 看extract变量覆盖这个的时候,代码里面出现了trim这个函数,就查了一下用法,说是去掉字符串开头和结尾的换行符或者是空格,还可以去掉不想出现的字符串。要说起来这个函数还是挺好理解的。就比如说最后一个吧,heordw,先从首开始看,到l的时候想去掉的字符串里面没有,所以到l的时候不再去掉任何字符,然后从尾往前看,是和首同样的道理 $str="helloeorldhelloworld"; echo trim($str,"herl");//oeorldhelloworld echo trim($str,"heorld");//w $str="helloeorlwdhelloworod"; echo trim($str,"heordw");//lloeorlwdhell file_get_contents($flag)//若是$flag的内容为字符串直接返回为空,若是txt的话能打开里面的内容。 extract($_GET)这个函数可以判断是get提交还是post提交,当为get提交时可以url中可以这样使用http://localhost/php/extract1.php?flag&shiyan #flag和shiyan是php中的两个变量。在extract()中,若是在url中有给变量赋值,则原本这个变量的值会被替换。可以预防被覆盖的方法是在php.ini这个文件中有register_globals这个变量的话将它改为off就行了,可能php版本问题,我的文件中没有这个变量。。。可能这个bug还是挺有用的。。 2.绕过过滤的空白字符 首先is_numeric这个函数要求的是为数字字符串,所以要想跳过这个函数可以加字母或者加一些编码后的符号。 然后$req['number']==strval(intval($req['number']))这个是要求输入的字符串取整和原本字符串相等,但是取整的时候若是有字母或是特殊字符直接截断了,若是构造这个数字100.000000000000010可以跳过这个函数,但是最开始的条件就跳不过了,若是在后面加上字母什么的可以跳过第一个,但是传入的字符串是存到数组中的,所以自己不会发生溢出情况。 $number[$i] !== $number[$j],后面的这个函数就容易实现了%00%0c191,%0c是\f的转义字符,%00的ascii值是0,后面的数字可以任意写,%00为截断,不能省略。 3.多重加密 这是题目给的加密方式 这是根据题目写出的解密方式 4.SQL注入_WITH ROLLUP绕过(实验吧 因缺思汀的绕过) $filter = "and|select|from|where|union|join|sleep|benchmark|,|\(|\)";这个是不能使用的单词。 mysql_num_rows($query) == 1//这个是要求函数返回结果集中行的数目必须为1 $key['pwd'] == $_POST['pwd']这个则是要求了提交的密码与数据库中的密码相等才能输出flag 当用rollup这个语句的时候,会在数据库的最后一行生成一个密码为NULL的字段 用下面这个payload ' or 1=1 group by pwd with rollup limit 1 offset 2 # 这样查询语句就会变成 SELECT * FROM interest WHERE uname = ' ' or 1=1 group by pwd with rollup limit 1 offset 2 # group by pwd with rollup 这个可以在数据库中添加一行pwd为NULL的数据,limit 1是之查询一行,offset 2这个数字可以换,不同的数字出现的是不同行的内容。 5.ereg正则%00截断 ereg ("^[a-zA-Z0-9]+$", $_GET['password']) === FALSE //这个函数要求输入的密码只能是大小写字母和数字 strlen($_GET['password']) < 8 && $_GET['password'] > 9999999这个要求了输入的密码长度小于8但是还得大于9999999,可以使用科学计数法表示,计算器或电脑表达10的的幂是一般是e strpos ($_GET['password'], '*-*') !== FALSE,strpos函数是查找后面的字符串在前面的字符串出现的位置,所以输入的密码中还得有*-*,但是前面的ereg函数过滤了特殊字符,这时候可以用ereg%00截断这个bug,ereg读到%00的时候,就截止了,所以1e9%00*-*就可以。 6.strcmp比较字符串 strcmp($_GET['a'], $flag) == 0// 参数 str1第一个字符串。str2第二个字符串。如果 str1 小于 str2 返回 < 0; 如果 str1 大于 str2 返回 > 0;只有两者相等,才返回 0。 strcmp只会处理字符串参数,如果给个数组的话,就会返回NULL,而判断使用是==,NULL==0是bool(true),所以构造这个函数a[]=1就行了。 7.sha1()函数比较绕过 $_GET['name'] == $_GET['password'])//若是传入的两个参数不同才能绕过这个函数 sha1($_GET['name']) === sha1($_GET['password']) sha1()函数默认的传入参数类型是字符串型,要是给它传入数组会出现错误,使sha1()函数返回错误,也就是返回false,这样一来===运算符就可以发挥作用了,需要构造username和password既不相等,又同样是数组类型 构造?name[]=1&password[]=12这样可以绕过 8.SESSION验证绕过 $_GET['password'] == $_SESSION['password']//在这个函数中,需要让提交的密码和session这个相等 ?password=这样构建并把cookie清空,刚开始我以为isset会把这个空的过滤掉,但虽然是空也没过滤。 9.密码md5比较绕过$pass = md5($_POST[pass]); $row = mysql_fetch_array($query, MYSQL_ASSOC); ($row[pw]) && (!strcasecmp($pass, $row[pw]))//这个就是构建一个数值和它的md5密码值 ?user=' union select '202cb962ac59075b964b07152d234b70' #&pass=123 10.urldecode二次编码绕过 eregi("hackerDJ",$_GET['id'] $_GET[id] = urldecode($_GET['id']); $_GET[id] == "hackerDJ" 这段代码是首先先匹配输入的值是否和hackerDJ相等,若是不等才可以继续下面的解码再让相等才可以,所以直接其中的一个字母编码两次就可以了。不知道为什么在php代码或者找的网站中都不能编码只能解码,所以看了原题目的wp。。不知道什么原因就是不能编码有点难受。。 http://localhost/php_bug/10.php/?id=%2568ackerDJ

优秀的个人博客,低调大师

Flink操作Hbase

现在有这样一个场景,我们需要将hbase做成一个数据流,而不是数据集。根据Flink自带的Flink-Hbase只能帮我们做到数据集,所以这个时候选择了重写Hbase的数据源。 package com.yjp.flink.demo11; import org.apache.flink.streaming.api.functions.source.SourceFunction; import org.apache.flink.table.shaded.org.joda.time.DateTime; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.KeyValue; import org.apache.hadoop.hbase.client.HTable; import org.apache.hadoop.hbase.client.Result; import org.apache.hadoop.hbase.client.ResultScanner; import org.apache.hadoop.hbase.client.Scan; import org.apache.hadoop.hbase.util.Bytes; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.IOException; import java.util.ArrayList; import java.util.List; /** * 以Hbase为数据源 * 从Hbase中获取数据,然后以流的形式发射 * Date : 9:50 2018/3/12 */ public class HbaseSource implements SourceFunction<String> { private static Logger loggerFactory = LoggerFactory.getLogger(HbaseSource.class); private static final long serialVersionUID = 1; private volatile boolean isRunning = true; /** * 开始的时间戳 */ private long startTime; /** * 每次查询多长时间的数据 */ private long interval; /** * 需要查询的列名 */ private ArrayList<String> columns; /** * 需要查询的表名 */ private String tableName; public HbaseSource(long startTime, long interval, ArrayList<String> columns, String tableName) { this.startTime = startTime; this.interval = interval; this.columns = columns; this.tableName = tableName; } public HbaseSource() { } @Override public void run(SourceContext<String> out) { if (isRunning) { long endTime = DateTime.now().getMillis() - interval; ResultScanner rs = new HbaseSource().getHbaseData(tableName, startTime, endTime - startTime, columns); new HbaseSource().transmitData(rs, out); startTime = endTime; } while (isRunning) { ResultScanner rs = new HbaseSource().getHbaseData(tableName, startTime, interval, columns); new HbaseSource().transmitData(rs, out); startTime += interval; try { Thread.sleep(interval); } catch (InterruptedException e) { throw new RuntimeException("休眠异常", e); } } } @Override public void cancel() { } /** * 获取数据集 * * @param startTime 时间戳开始的时间 * @param interval 间隔时间 * @return 对应的结果集 */ private ResultScanner getHbaseData(String tableName, long startTime, long interval, List<String> columns) { Configuration conf = HBaseConfiguration.create(); HTable table; Scan scan; try { table = new HTable(conf, tableName); scan = new Scan(); scan.setTimeRange(startTime, startTime + interval); for (String column : columns) { String[] columnName = column.split(":"); scan.addColumn(Bytes.toBytes(columnName[0]), Bytes.toBytes(columnName[1])); } return table.getScanner(scan); } catch (IOException e) { throw new RuntimeException("读取数据异常", e); } } private void transmitData(ResultScanner rs, SourceContext<String> out) { Result result; try { while ((result = rs.next()) != null && isRunning) { KeyValue[] kvs = result.raw(); for (KeyValue kv : kvs) { String value = new String(kv.getValue()); out.collect(value); } } } catch (IOException e) { throw new RuntimeException("结果集遍历异常", e); } } } 然后将数据结果加工和处理存入Hbase中 package com.yjp.flink.hbase; import org.apache.flink.api.common.functions.FlatMapFunction; import org.apache.flink.api.java.tuple.Tuple2; import org.apache.flink.api.java.tuple.Tuple3; import org.apache.flink.streaming.api.datastream.DataStream; import org.apache.flink.streaming.api.datastream.DataStreamSource; import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; import org.apache.flink.table.api.Table; import org.apache.flink.table.api.java.StreamTableEnvironment; import org.apache.flink.util.Collector; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.ArrayList; import java.util.List; public class HbaseToHbase { public static Logger logger = LoggerFactory.getLogger(HbaseToHbase.class); public static void main(String[] args) throws Exception { StreamExecutionEnvironment sEnv = StreamExecutionEnvironment.getExecutionEnvironment(); StreamTableEnvironment tEnv = StreamTableEnvironment.getTableEnvironment(sEnv); sEnv.getConfig().disableSysoutLogging(); List<String> getColumns = new ArrayList<String>(3); getColumns.add("cf1_name"); getColumns.add("cf2_amount"); getColumns.add("cf3_groupId"); List<String> columnFamily = new ArrayList<>(3); columnFamily.add("cf1"); columnFamily.add("cf2"); columnFamily.add("cf3"); List<String> setColumns = new ArrayList<>(3); setColumns.add("cf2:result"); DataStreamSource<Orders> orderDataStream = sEnv.addSource(new HbaseStreamDataSource("Orders", 0L, 2000L, getColumns, Orders.class)); DataStream<Tuple3<String, Double, Integer>> dataStream = orderDataStream.flatMap( new FlatMapFunction<Orders, Tuple3<String, Double, Integer>>() { @Override public void flatMap(Orders value, Collector<Tuple3<String, Double, Integer>> out) throws Exception { out.collect(new Tuple3<String, Double, Integer>(value.getCf1_name(), value.getCf2_amount(), value.getCf3_groupId())); } }); dataStream.keyBy(2).sum(1).addSink( new SinkHbase<Tuple3<String, Double, Integer>>( "OrderResult", columnFamily, setColumns, "result")); sEnv.execute("test Hbase"); } } package com.yjp.flink.hbase; import org.apache.flink.api.java.tuple.*; import org.apache.flink.configuration.Configuration; import org.apache.flink.streaming.api.functions.sink.RichSinkFunction; import org.apache.hadoop.hbase.HColumnDescriptor; import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.Admin; import org.apache.hadoop.hbase.client.Table; import java.lang.reflect.Method; import java.util.*; /** * 自定义Sink * * Date : 17:23 2018/3/12 */ public class SinkHbase<T> extends RichSinkFunction<T> { private static final long serialVersionUID = 1L; /** * 表名 */ private String tableName; /** * 列族名 */ private List<String> columnFails; /** * 列名 以 family:column的形式传入 column与tuple中的值一一对应 */ private List<String> columns; /** * 行名 */ private String rowKey; /** * @param tableName 表名 * @param columnFamily 列族名 当表存在时不用输入 * @param columns 储存的列名 列族:列名 * @param rowKey 传入的行名 */ public SinkHbase(String tableName, List<String> columnFamily, List<String> columns, String rowKey) { this.tableName = tableName; this.columnFails = columnFamily; this.columns = columns; this.rowKey = rowKey; } /** * @param tableName 表名 * @param columns 储存的列名 列族:列名 * @param rowKey 传入的行名 */ public SinkHbase(String tableName, List<String> columns, String rowKey) { this.tableName = tableName; this.columns = columns; this.rowKey = rowKey; } public SinkHbase() { } /** * 初始化完成连接 当表不存在的时候 新建表和family列 * * @param parameters 调用父类的方法 * @throws Exception 创建连接失败 */ @Override public void open(Configuration parameters) throws Exception { super.open(parameters); Admin admin = FactoryConnect.getConnection().getAdmin(); final TableName tableName1 = TableName.valueOf(tableName); if (!admin.tableExists(tableName1)) { HTableDescriptor hTableDescriptor = new HTableDescriptor(tableName1); for (String columnFamily : columnFails) { hTableDescriptor.addFamily(new HColumnDescriptor(columnFamily)); } admin.createTable(hTableDescriptor); } } /** * 执行方法 将数据存入hbase * * @param value 传入的结果 */ @Override public void invoke(T value, Context context) throws Exception { Map<Class, Method> map = new HashMap<>(25); new SinkHbase<T>().initMap(map); Table table = FactoryConnect.getConnection().getTable(TableName.valueOf(tableName)); Set<Class> keys = map.keySet(); for (Class key : keys) { if (value.getClass() == key) { map.get(key).invoke(new AssignmentTuple(), value, rowKey, columns, table); return; } } } private void initMap(Map<Class, Method> map) { try { map.put(Tuple1.class, AssignmentTuple.class.getMethod("setTuple1", Tuple1.class, String.class, ArrayList.class, Table.class)); map.put(Tuple2.class, AssignmentTuple.class.getMethod("setTuple2", Tuple2.class, String.class, ArrayList.class, Table.class)); map.put(Tuple3.class, AssignmentTuple.class.getMethod("setTuple3", Tuple3.class, String.class, ArrayList.class, Table.class)); map.put(Tuple4.class, AssignmentTuple.class.getMethod("setTuple4", Tuple4.class, String.class, ArrayList.class, Table.class)); map.put(Tuple5.class, AssignmentTuple.class.getMethod("setTuple5", Tuple5.class, String.class, ArrayList.class, Table.class)); map.put(Tuple6.class, AssignmentTuple.class.getMethod("setTuple6", Tuple6.class, String.class, ArrayList.class, Table.class)); map.put(Tuple7.class, AssignmentTuple.class.getMethod("setTuple7", Tuple7.class, String.class, ArrayList.class, Table.class)); map.put(Tuple8.class, AssignmentTuple.class.getMethod("setTuple8", Tuple8.class, String.class, ArrayList.class, Table.class)); map.put(Tuple9.class, AssignmentTuple.class.getMethod("setTuple9", Tuple9.class, String.class, ArrayList.class, Table.class)); map.put(Tuple10.class, AssignmentTuple.class.getMethod("setTuple10", Tuple10.class, String.class, ArrayList.class, Table.class)); map.put(Tuple11.class, AssignmentTuple.class.getMethod("setTuple11", Tuple11.class, String.class, ArrayList.class, Table.class)); map.put(Tuple12.class, AssignmentTuple.class.getMethod("setTuple12", Tuple12.class, String.class, ArrayList.class, Table.class)); map.put(Tuple13.class, AssignmentTuple.class.getMethod("setTuple13", Tuple13.class, String.class, ArrayList.class, Table.class)); map.put(Tuple14.class, AssignmentTuple.class.getMethod("setTuple14", Tuple14.class, String.class, ArrayList.class, Table.class)); map.put(Tuple15.class, AssignmentTuple.class.getMethod("setTuple15", Tuple15.class, String.class, ArrayList.class, Table.class)); map.put(Tuple16.class, AssignmentTuple.class.getMethod("setTuple16", Tuple16.class, String.class, ArrayList.class, Table.class)); map.put(Tuple17.class, AssignmentTuple.class.getMethod("setTuple17", Tuple17.class, String.class, ArrayList.class, Table.class)); map.put(Tuple18.class, AssignmentTuple.class.getMethod("setTuple18", Tuple18.class, String.class, ArrayList.class, Table.class)); map.put(Tuple19.class, AssignmentTuple.class.getMethod("setTuple19", Tuple19.class, String.class, ArrayList.class, Table.class)); map.put(Tuple20.class, AssignmentTuple.class.getMethod("setTuple20", Tuple20.class, String.class, ArrayList.class, Table.class)); map.put(Tuple21.class, AssignmentTuple.class.getMethod("setTuple21", Tuple21.class, String.class, ArrayList.class, Table.class)); map.put(Tuple22.class, AssignmentTuple.class.getMethod("setTuple22", Tuple22.class, String.class, ArrayList.class, Table.class)); map.put(Tuple23.class, AssignmentTuple.class.getMethod("setTuple23", Tuple23.class, String.class, ArrayList.class, Table.class)); map.put(Tuple24.class, AssignmentTuple.class.getMethod("setTuple24", Tuple24.class, String.class, ArrayList.class, Table.class)); map.put(Tuple25.class, AssignmentTuple.class.getMethod("setTuple25", Tuple25.class, String.class, ArrayList.class, Table.class)); } catch (NoSuchMethodException e) { throw new RuntimeException("反射失败", e); } } } package com.yjp.flink.hbase; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.client.Connection; import org.apache.hadoop.hbase.client.ConnectionFactory; import java.io.IOException; import java.io.Serializable; /** * 单例模式 安全的拿到连接 * * Date : 16:45 2018/3/16 */ public class FactoryConnect implements Serializable { private static volatile Connection connection; private FactoryConnect() { } public static Connection getConnection() throws IOException { if (null == connection) { synchronized (FactoryConnect.class) { try { if (null == connection) { org.apache.hadoop.conf.Configuration conf = HBaseConfiguration.create(); connection = ConnectionFactory.createConnection(conf); } } catch (Exception e) { System.err.println("读取配置文件异常"); } } } return connection; } } package com.yjp.flink.hbase; import org.apache.flink.api.java.tuple.*; import org.apache.hadoop.hbase.client.Put; import org.apache.hadoop.hbase.client.Table; import org.apache.hadoop.hbase.util.Bytes; import java.io.IOException; import java.time.Instant; import java.util.ArrayList; import java.util.List; /** * 将tuple中的存放在Hbase中 * * Date : 16:49 2018/3/12 */ public class AssignmentTuple { /** * tuple 为1 * * @param tuple1 传入tuple的值 * @param rowKey 传入的rowkey的值 * @param columns 需要赋值的列 * @param table put的table对象 */ public void setTuple1(Tuple1<Object> tuple1, String rowKey, ArrayList<String> columns, Table table) { new AssignmentTuple().putData(tuple1, rowKey, columns, table); } public void setTuple2(Tuple2<Object, Object> tuple2, String rowKey, ArrayList<String> columns, Table table) { new AssignmentTuple().putData(tuple2, rowKey, columns, table); } public void setTuple3(Tuple3<Object, Object, Object> tuple3, String rowKey, ArrayList<String> columns, Table table) { new AssignmentTuple().putData(tuple3, rowKey, columns, table); } public void setTuple4(Tuple4<Object, Object, Object, Object> tuple4, String rowKey, ArrayList<String> columns, Table table) { new AssignmentTuple().putData(tuple4, rowKey, columns, table); } public void setTuple5(Tuple5<Object, Object, Object, Object, Object> tuple5, String rowKey, ArrayList<String> columns, Table table) { new AssignmentTuple().putData(tuple5, rowKey, columns, table); } public void setTuple6(Tuple6 tuple6, String rowKey, ArrayList<String> columns, Table table) { new AssignmentTuple().putData(tuple6, rowKey, columns, table); } public void setTuple7(Tuple7 tuple7, String rowKey, ArrayList<String> columns, Table table) { new AssignmentTuple().putData(tuple7, rowKey, columns, table); } public void setTuple8(Tuple8 tuple8, String rowKey, ArrayList<String> columns, Table table) { new AssignmentTuple().putData(tuple8, rowKey, columns, table); } public void setTuple9(Tuple9 tuple9, String rowKey, ArrayList<String> columns, Table table) { new AssignmentTuple().putData(tuple9, rowKey, columns, table); } public void setTuple10(Tuple10 tuple10, String rowKey, ArrayList<String> columns, Table table) { new AssignmentTuple().putData(tuple10, rowKey, columns, table); } public void setTuple11(Tuple11 tuple11, String rowKey, ArrayList<String> columns, Table table) { new AssignmentTuple().putData(tuple11, rowKey, columns, table); } public void setTuple12(Tuple12 tuple12, String rowKey, ArrayList<String> columns, Table table) { new AssignmentTuple().putData(tuple12, rowKey, columns, table); } public void setTuple13(Tuple13 tuple13, String rowKey, ArrayList<String> columns, Table table) { new AssignmentTuple().putData(tuple13, rowKey, columns, table); } public void setTuple14(Tuple14 tuple14, String rowKey, ArrayList<String> columns, Table table) { new AssignmentTuple().putData(tuple14, rowKey, columns, table); } public void setTuple15(Tuple15 tuple15, String rowKey, ArrayList<String> columns, Table table) { new AssignmentTuple().putData(tuple15, rowKey, columns, table); } public void setTuple16(Tuple16 tuple16, String rowKey, ArrayList<String> columns, Table table) { new AssignmentTuple().putData(tuple16, rowKey, columns, table); } public void setTuple17(Tuple17 tuple17, String rowKey, ArrayList<String> columns, Table table) { new AssignmentTuple().putData(tuple17, rowKey, columns, table); } public void setTuple18(Tuple18 tuple18, String rowKey, ArrayList<String> columns, Table table) { new AssignmentTuple().putData(tuple18, rowKey, columns, table); } public void setTuple19(Tuple19 tuple19, String rowKey, ArrayList<String> columns, Table table) { new AssignmentTuple().putData(tuple19, rowKey, columns, table); } public void setTuple20(Tuple20 tuple20, String rowKey, ArrayList<String> columns, Table table) { new AssignmentTuple().putData(tuple20, rowKey, columns, table); } public void setTuple21(Tuple21 tuple21, String rowKey, ArrayList<String> columns, Table table) { new AssignmentTuple().putData(tuple21, rowKey, columns, table); } public void setTuple22(Tuple22 tuple22, String rowKey, ArrayList<String> columns, Table table) { new AssignmentTuple().putData(tuple22, rowKey, columns, table); } public void setTuple23(Tuple23 tuple23, String rowKey, ArrayList<String> columns, Table table) { new AssignmentTuple().putData(tuple23, rowKey, columns, table); } public void setTuple24(Tuple24 tuple24, String rowKey, ArrayList<String> columns, Table table) { new AssignmentTuple().putData(tuple24, rowKey, columns, table); } public void setTuple25(Tuple25 tuple25, String rowKey, ArrayList<String> columns, Table table) { new AssignmentTuple().putData(tuple25, rowKey, columns, table); } /** * 将tuple中的数据一一对应的赋值给列 * * @param tuple tuple中的数据 * @param rowKey 设置的行值 * @param columns 对应的列名 * @param table 对应的table对象 */ public void putData(Tuple tuple, String rowKey, List<String> columns, Table table) { Put put = new Put(Bytes.toBytes(rowKey)); Long timeStamp = Instant.now().toEpochMilli(); for (int i = 0; i < columns.size(); i++) { String[] split = columns.get(i).split(":"); put.addColumn(Bytes.toBytes(split[0]), Bytes.toBytes(split[1]), timeStamp, Bytes.toBytes(tuple.getField(i).toString())); } try { table.put(put); } catch (IOException e) { throw new RuntimeException("存放失败", e); } } } 为了做到一个通用的数据源和数据存储,于是采用了反射的方法。

优秀的个人博客,低调大师

数据集操作

代码运行报错: ----------> Parent Classloader: java.net.URLClassLoader@1c53fd30 : java.lang.ClassNotFoundException: org.springframework.dao.TransientDataAccessResourceException 八月 10, 2018 5:45:28 下午 com.caucho.hessian.io.SerializerFactory getDeserializer 警告: Hessian/Burlap: 'org.springframework.dao.TransientDataAccessResourceException' is an unknown class in ParallelWebappClassLoader context: cc-web delegate: false ----------> Parent Classloader: java.net.URLClassLoader@1c53fd30 : java.lang.ClassNotFoundException: org.springframework.dao.TransientDataAccessResourceException com.weibo.api.motan.exception.MotanServiceException: error_message: biz exception cause is throwable error:class java.lang.Throwable, errmsg:PreparedStatementCallback; SQL [SELECT `free_pricing` FROM `account` WHERE `account_id`=?]; Before start of result set, status: 503, error_code: 10001,r=null at com.weibo.api.motan.proxy.RefererInvocationHandler.invoke(RefererInvocationHandler.java:127) at com.sun.proxy.$Proxy71.getFreePricingStatus(Unknown Source) at com.btzh.resource.ProfileResource.toCopyright(ProfileResource.java:285) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory$1.invoke(ResourceMethodInvocationHandlerFactory.java:81) 代码是很简单的一个sql查询: @Override public YesOrNo getFreePricingStatus(Integer accountId) { return jdbcTemplate.query("SELECT `free_pricing` FROM `account` WHERE `account_id`=?", new Object[] { accountId }, new ResultSetExtractor<YesOrNo>() { @Override public YesOrNo extractData(ResultSet rs) throws SQLException, DataAccessException { return YesOrNo.getByValue(rs.getInt("free_pricing")); } }); } 单元测试没有任何问题, 放到项目中运行就出现上面的报错. 后来想是不是因为缺少rs.next(), 导致指针仍然在第一个元素的前一个位置, 导致指针没有下移, 改了下: @Override public YesOrNo getFreePricingStatus(Integer accountId) { return jdbcTemplate.query("SELECT `free_pricing` FROM `account` WHERE `account_id`=?", new Object[] { accountId }, new ResultSetExtractor<YesOrNo>() { @Override public YesOrNo extractData(ResultSet rs) throws SQLException, DataAccessException { if (rs.next()) { return YesOrNo.getByValue(rs.getInt("free_pricing")); } return YesOrNo.NO; } }); } 好了. 但是没想清楚为什么单元测试没有报错, 待续.

优秀的个人博客,低调大师

python操作csv

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_34173549/article/details/81285438 '''def build_excel(self): workbook = xlwt.Workbook(encoding='ascii') # 创建表 worksheet = workbook.add_sheet('My Worksheet') # 往表写内容 行 ,列 worksheet.write(1, 3, label='Row 0, Column 0 Value') workbook.save('Excel_Workbook.xlsx') csvFile = open("test42.cs v", 'w', newline='') try: writer = csv.writer(csvFile) writer.writerow(('id', '标题', '发布时间','视频时长', '播放次数', '评论数', '喜欢数', '分享数', '上传用户', '下载地址' )) for i in range(10): writer.writerow((1, 2, 3, 4, 5, 6, 7, 8, 9, 10)) finally: csvFile.close() return csvFile;

优秀的个人博客,低调大师

Hive常用操作

1. 绑定数据 1.1 创建表&创建文本文件 create table fantj.t3(id int,name string,age int) row format delimited fields terminated by ','stored as textfile; hive> create table fantj.t3(id int,name string,age int) row format delimited fields terminated by ','stored as textfile; OK Time taken: 4.467 seconds hive> select * from fantj.t3; OK Time taken: 2.82 seconds 表示行格式用逗号来分割字段。 创建文本文件test.txt 我创建在/home/fantj目录下。 1,jiao,18 2,fantj,20 3,laowang,30 4,laotie,40 1.2 从本地导入到hive LOAD DATA LOCAL INPATH '/home/fantj/test.txt' OVERWRITE INTO TABLE t3; hive> LOAD DATA LOCAL INPATH '/home/fantj/test.txt' OVERWRITE INTO TABLE fantj.t3; Loading data to table fantj.t3 [Warning] could not update stats. OK Time taken: 26.334 seconds select * from fantj.t3; hive> select * from fantj.t3; OK 1 jiao 18 2 fantj 20 3 laowang 30 4 laotie 40 Time taken: 2.303 seconds, Fetched: 4 row(s) 导入成功! 1.3 从hdfs导入到hive 先将test文件上传到hdfs中 [root@s166 fantj]# hadoop fs -put test.txt /hdfs2hive -rw-r--r-- 3 root supergroup 46 /hdfs2hive/test.txt 进入hive,创建表t5 create table fantj.t5(id int,name string,age int) row format delimited fields terminated by ','stored as textfile; hive> create table fantj.t5(id int,name string,age int) row format delimited fields terminated by ','stored as textfile; OK Time taken: 3.214 seconds 执行导入 LOAD DATA INPATH '/hdfs2hive/test.txt' OVERWRITE INTO TABLE fantj.t5; hive> LOAD DATA INPATH '/hdfs2hive/test.txt' OVERWRITE INTO TABLE fantj.t5; Loading data to table fantj.t5 [Warning] could not update stats. OK Time taken: 25.498 seconds 检查是否成功: hive> select * from fantj.t5; OK 1 jiao 18 2 fantj 20 3 laowang 30 4 laotie 40 Time taken: 5.046 seconds, Fetched: 4 row(s)

优秀的个人博客,低调大师

Python操作MySql

一、linux客户端连接mssql server 1.linux下安装unixODBC 2.linux安装FreeTDS (1) 配置FreeTDS。 /etc/freetds/freetds.conf [egServer70] host = server ip port = 1433 tds Version = 7.0 [dsnName] host = server ip port = 1433 tds Version = 8.0 client charset = UTF-8 (2)配置odbc /etc/odbc.ini [dsnName] Driver = FreeTDS Description = Odbc connection via FreeTDS Trace = No Servername = dsnName Database = oneicdb (3)配置odbc /etc/odbc [FreeTDS] Description = FreeTDS Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so setup = /usr/lib/x86_64-linux-gnu/odbc/libtdsS.so FileUsage = 1 CPTimeout = CPResure = client charset = utf-8 UsageCount = 1 [SQL Server] Description = FreeTDS ODBC driver for MSSQL Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so Setup = /usr/lib/x86_64-linux-gnu/odbc/libtdsS.so FileUsage = 1 import pyodbc strconn= 'DRIVER={SQL Server};SERVER=.;DATABASE=test;UID=sa;PWD=sa' db = pyodbc.connect(strconn) c = db.cursor() sql = '.....................' c.execute(sql) c.fetchone() c.fetchall() c.close() db.close() 存储过程调用:c.execute("{call sp_MemberAdrInsert_py (?,?,?,?,?,?,?,?,?,?)}", ('a','b','c','d','e','f','g','h','100086',0)) 1、存储过程可以直接返回值,如果返回一个值,那么存储过程里必须有:SET NOCOUNT ON 2、存储过程不可以output值 Welcome to Python world! I have a contract in this world! How about you?

资源下载

更多资源
腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

用户登录
用户注册