Skip to content

Commit ca3fa97

Browse files
authored
Update HFP.go
Critical update for saving to file leackage
1 parent 3671a07 commit ca3fa97

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

HFP.go

+7-8
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
"time"
1515
)
1616

17-
const AppVersion = "0.54"
17+
const AppVersion = "0.55"
1818

1919
var localAddr *string = flag.String("l", ":9060", "Local HEP listening address")
2020
var remoteAddr *string = flag.String("r", "192.168.2.2:9060", "Remote HEP address")
@@ -68,16 +68,15 @@ func initLoopbackConn(wg *sync.WaitGroup) {
6868

6969
}
7070

71-
func copyHEPbufftoFile(inbytes []byte, file string) (int64, error) {
71+
func copyHEPbufftoFile(inbytes *net.TCPConn, file string) (int64, error) {
7272

7373
destination, err := os.OpenFile(file, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666)
7474
if err != nil {
7575
fmt.Println("Open HEP file error", err)
7676
}
7777

7878
defer destination.Close()
79-
nBytes, err := destination.Write(inbytes)
80-
79+
nBytes, err := io.Copy(destination, inbytes)
8180
if err != nil {
8281
log.Println("||-->X File Send HEP from buffer to file error", err)
8382
} else {
@@ -168,7 +167,7 @@ func proxyConn(conn *net.TCPConn) {
168167
for _, ipf := range filterIPs {
169168
if ((hepPkt.SrcIP == string(ipf) || hepPkt.DstIP == string(ipf)) && *IPfilter != "" && *IPfilterAction == "pass") || (*IPfilter == "" || (hepPkt.SrcIP != string(ipf) || hepPkt.DstIP != string(ipf)) && *IPfilter != "" && *IPfilterAction == "reject") {
170169

171-
go copyHEPbufftoFile(buf[:data], HEPsavefile)
170+
go copyHEPbufftoFile(conn, HEPsavefile)
172171
}
173172
}
174173

@@ -237,7 +236,7 @@ func proxyConn(conn *net.TCPConn) {
237236
if _, err_HEPout := fmt.Fprint(rConn, string(buf[:data])); err_HEPout != nil {
238237
log.Println("||--> Sending HEP OUT error:", err_HEPout)
239238
// rb := bytes.NewReader(buf[:data])
240-
go copyHEPbufftoFile(buf[:data], HEPsavefile)
239+
go copyHEPbufftoFile(conn, HEPsavefile)
241240
accepted = true
242241
return
243242
} else {
@@ -289,7 +288,7 @@ func proxyConn(conn *net.TCPConn) {
289288
if _, err_HEPout := fmt.Fprint(rConn, string(buf[:data])); err_HEPout != nil {
290289
log.Println("||--> Sending HEP OUT error:", err_HEPout)
291290
//rb := bytes.NewReader(buf[:data])
292-
go copyHEPbufftoFile(buf[:data], HEPsavefile)
291+
go copyHEPbufftoFile(conn, HEPsavefile)
293292
return
294293
} else {
295294
if *Debug == "on" {
@@ -303,7 +302,7 @@ func proxyConn(conn *net.TCPConn) {
303302
if _, err_HEPout := fmt.Fprint(rConn, string(buf[:data])); err_HEPout != nil {
304303
log.Println("||--> Sending HEP OUT error:", err_HEPout)
305304
// rb := bytes.NewReader(buf[:data])
306-
go copyHEPbufftoFile(buf[:data], HEPsavefile)
305+
go copyHEPbufftoFile(conn, HEPsavefile)
307306
return
308307
} else {
309308
if *Debug == "on" {

0 commit comments

Comments
 (0)