作者:zzz19760225 | 时间:2016-10-21 23:22 | 标题:2274.7z_data_2~7
package main
import (
"fmt"
)
func VESAtoVT100(code byte) string {
colors := []int{0, 4, 2, 6, 1, 5, 3, 7, 0, 4, 2, 6, 1, 5, 3, 7}
bg := colors[(code&0xF0)>>4]
fg := colors[code&0x0F]
return fmt.Sprintf("\x1B[4%d;3%dm", bg, fg)
/*
Set Display Attributes
Set Attribute Mode <ESC>[{attr1};...;{attrn}m
Sets multiple display attribute settings. The following lists standard attributes:
0 Reset all attributes
1 Bright
2 Dim
4 Underscore
5 Blink
7 Reverse
8 Hidden
Foreground Colours
30 Black
31 Red
32 Green
33 Yellow
34 Blue
35 Magenta
36 Cyan
37 White
Background Colours
40 Black
41 Red
42 Green
43 Yellow
44 Blue
45 Magenta
46 Cyan
47 White
*/
}
func CorrectBadChars(in byte) string {
data := []string{" ", "鈽?, "鈽?, "鈾?, "鈾?, "鈾?, "鈾?, "鈥?, "鈼?,
"鈼?, "鈼?, "鈾?, "鈾€", "鈾?, "鈾?, "鈽?, "鈻?, "鈼?, "鈫?, "鈥?, "露", "搂",
"鈻?, "鈫?, "鈫?, "鈫?, "鈫?, "鈫?, "鈭?, "鈫?, "鈻?, "鈻?, " ", "!", "\"",
"#", "$", "%", "&", "'", "(", ")", "*", "+", ",", "-", ".", "/",
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", ":", ";", "<",
"=", ">", "?", "@", "A", "B", "C", "D", "E", "F", "G", "H", "I",
"J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V",
"W", "X", "Y", "Z", "[", "\\", "]", "^", "_", "`", "a", "b", "c",
"d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p",
"q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "{", "|", "}",
"~", "鈱?, "脟", "眉", "茅", "芒", "盲", "脿", "氓", "莽", "锚", "毛", "猫",
"茂", "卯", "矛", "脛", "脜", "脡", "忙", "脝", "么", "枚", "貌", "没", "霉",
"每", "脰", "脺", "垄", "拢", "楼", "鈧?, "茠", "谩", "铆", "贸", "煤", "帽",
"脩", "陋", "潞", "驴", "鈱?, "卢", "陆", "录", "隆", "芦", "禄", "鈻?, "鈻?,
"鈻?, "鈹?, "鈹?, "鈺?, "鈺?, "鈺?, "鈺?, "鈺?, "鈺?, "鈺?, "鈺?, "鈺?, "鈺?,
"鈹?, "鈹?, "鈹?, "鈹?, "鈹?, "鈹€", "鈹?, "鈺?, "鈺?, "鈺?, "鈺?, "鈺?, "鈺?,
"鈺?, "鈺?, "鈺?, "鈺?, "鈺?, "鈺?, "鈺?, "鈺?, "鈺?, "鈺?, "鈺?, "鈺?, "鈺?,
"鈹?, "鈹?, "鈻?, "鈻?, "鈻?, "鈻?, "鈻€", "伪", "脽", "螕", "蟺", "危", "蟽",
"碌", "蟿", "桅", "螛", "惟", "未", "鈭?, "蠁", "蔚", "鈭?, "鈮?, "卤", "鈮?,
"鈮?, "鈱?, "鈱?, "梅", "鈮?, "掳", "鈭?, "路", "鈭?, "鈦?, "虏", "鈻?, "\n", " "}
return data[uint8(in)]
}
作者:zzz19760225 | 时间:2016-10-21 23:27 | 标题:2274.7z_ssh_6~7
package main
import (
"golang.org/x/crypto/ssh"
"log"
"net"
"time"
)
var FrameBufferUpdate chan []byte
var FrameBufferSubscribers map[string]chan []byte
// Start listening for SSH connections
func StartSSH() {
PEM_KEY := LoadPrivKeyFromFile("./id_rsa")
private, err := ssh.ParsePrivateKey(PEM_KEY)
if err != nil {
log.Fatal("Key failed to parse.")
}
SSHConfig := &ssh.ServerConfig{
PasswordCallback: func(conn ssh.ConnMetadata, pass []byte) (*ssh.Permissions, error) {
perms := ssh.Permissions{}
return &perms, nil
},
PublicKeyCallback: func(conn ssh.ConnMetadata, key ssh.PublicKey) (*ssh.Permissions, error) {
perms := ssh.Permissions{}
return &perms, nil
},
}
SSHConfig.AddHostKey(private)
listener, err := net.Listen("tcp", "0.0.0.0:2222")
if err != nil {
log.Fatalln("Could not start TCP listening on 0.0.0.0:2222")
}
log.Println("Waiting for TCP conns on 0.0.0.0:2222")
for {
nConn, err := listener.Accept()
if err != nil {
log.Println("WARNING - Failed to Accept TCP conn. RSN: %s / %s", err.Error(), err)
continue
}
go HandleIncomingSSHConn(nConn, SSHConfig)
}
}
// Wait 10 seconds before closing the connection (To stop dead connections)
func TimeoutConnection(Done chan bool, nConn net.Conn) {
select {
case <-Done:
return
case <-time.After(time.Second * 10):
nConn.Close()
}
}
func HandleIncomingSSHConn(nConn net.Conn, config *ssh.ServerConfig) {
DoneCh := make(chan bool)
go TimeoutConnection(DoneCh, nConn)
_, chans, reqs, err := ssh.NewServerConn(nConn, config)
if err == nil {
DoneCh <- true
}
// Right now that we are out of annoying people land.
defer nConn.Close()
go HandleSSHrequests(reqs)
for newChannel := range chans {
if newChannel.ChannelType() != "session" {
newChannel.Reject(ssh.UnknownChannelType, "unknown channel type")
log.Printf("WARNING - Rejecting %s Because they asked for a chan type %s that I don't have", nConn.RemoteAddr().String(), newChannel.ChannelType())
continue
}
channel, requests, err := newChannel.Accept()
if err != nil {
log.Printf("WARNING - Was unable to Accept channel with %s", nConn.RemoteAddr().String())
return
}
go HandleSSHrequests(requests)
go ServeDOSTerm(channel)
}
}
func HandleSSHrequests(in <-chan *ssh.Request) {
for req := range in {
if req.WantReply {
// Ensure that the other end does not panic that we don't offer terminals
if req.Type == "shell" || req.Type == "pty-req" {
req.Reply(true, nil)
} else {
req.Reply(false, nil)
}
}
}
}